Compare commits

..

No commits in common. "0ba9416a57c86feb5dbbac8439e9775742043227" and "c0a622c5e43e4f8df8485c97f3e1469667307fff" have entirely different histories.

6 changed files with 28 additions and 39 deletions

View File

@ -5,14 +5,14 @@
#include <catch2/catch.hpp> #include <catch2/catch.hpp>
#ifdef NDEBUG #ifdef NDEBUG
#undef NDEBUG # undef NDEBUG
#define NDEBUG_WAS_SET # define NDEBUG_WAS_SET
#endif #endif
#include "utility_assert.hpp" #include "utility_assert.hpp"
#ifdef NDEBUG_WAS_SET #ifdef NDEBUG_WAS_SET
#define NDEBUG # define NDEBUG
#endif #endif
namespace namespace
@ -20,12 +20,12 @@ namespace
bool assert_flag = false; bool assert_flag = false;
void assertCallback(const char*, const char*, const int) void assertCallback(const char*, const int)
{ {
assert_flag = true; assert_flag = true;
} }
}// namespace }
TEST_CASE("Assert debug without NDEBUG gets triggered if check is false.", "[utility],[assert]") TEST_CASE("Assert debug without NDEBUG gets triggered if check is false.", "[utility],[assert]")
{ {

View File

@ -5,14 +5,14 @@
#include <catch2/catch.hpp> #include <catch2/catch.hpp>
#ifndef NDEBUG #ifndef NDEBUG
#define NDEBUG # define NDEBUG
#define NDEBUG_WAS_NOT_DEFINED # define NDEBUG_WAS_NOT_DEFINED
#endif #endif
#include "utility_assert.hpp" #include "utility_assert.hpp"
#ifdef NDEBUG_WAS_NOT_DEFINED #ifdef NDEBUG_WAS_NOT_DEFINED
#undef NDEBUG # undef NDEBUG
#endif #endif
namespace namespace
@ -20,12 +20,12 @@ namespace
bool assert_flag = false; bool assert_flag = false;
void assertCallback(const char*, const char*, const int) void assertCallback(const char*, const int)
{ {
assert_flag = true; assert_flag = true;
} }
}// namespace }
TEST_CASE("Assert debug with NDEBUG is a null-opt.", "[utility],[assert]") TEST_CASE("Assert debug with NDEBUG is a null-opt.", "[utility],[assert]")
{ {

View File

@ -8,26 +8,26 @@
namespace Utility::Assert::Detail namespace Utility::Assert::Detail
{ {
void assertImpl(const char* expression, const char* file, const int line); void assertImpl(const bool expr, const char* file, const int line);
} }
#ifndef NDEBUG #ifndef NDEBUG
#define SKULLC_ASSERT_DEBUG(e) (!(e) ? Utility::Assert::Detail::assertImpl(#e, __FILE__, __LINE__) : ((void) 0)) # define SKULLC_ASSERT_DEBUG(e) Utility::Assert::Detail::assertImpl(e, __FILE__, __LINE__)
#else #else
#define SKULLC_ASSERT_DEBUG(e) # define SKULLC_ASSERT_DEBUG(e)
#endif #endif
#define SKULLC_ASSERT_SAFE(e) (!(e) ? Utility::Assert::Detail::assertImpl(#e, __FILE__, __LINE__) : ((void) 0)) #define SKULLC_ASSERT_SAFE(e) Utility::Assert::Detail::assertImpl(e, __FILE__, __LINE__)
namespace Utility::Assert namespace Utility::Assert
{ {
using assert_cb = void (*)(const char* expression, const char* file, const int line); using assert_cb = void (*)(const char* file, const int line);
void setHandler(assert_cb callback); void setHandler(assert_cb callback);
assert_cb getHandler(); assert_cb getHandler();
}// namespace Utility::Assert }
#endif// SKULLC_UTILITY_ASSERT_HPP_ #endif // SKULLC_UTILITY_ASSERT_HPP_

View File

@ -8,11 +8,8 @@
#ifndef SKULLC_UTILITY_STATICPOINTER_HPP_ #ifndef SKULLC_UTILITY_STATICPOINTER_HPP_
#define SKULLC_UTILITY_STATICPOINTER_HPP_ #define SKULLC_UTILITY_STATICPOINTER_HPP_
#include <new>
#include <utility> #include <utility>
#include <utility_assert.hpp>
namespace Utility namespace Utility
{ {
@ -60,17 +57,6 @@ struct StaticPointer
return initialized_; return initialized_;
} }
value_type* get()
{
SKULLC_ASSERT_DEBUG(initialized_);
return reinterpret_cast<value_type*>(storage);
}
const value_type* get() const
{
SKULLC_ASSERT_DEBUG(initialized_);
return reinterpret_cast<const value_type*>(storage);
}
private: private:
bool initialized_ = false; bool initialized_ = false;
}; };

View File

@ -9,4 +9,4 @@
#define SKULLC_CONCAT(x, y) SKULLC_CONCAT_IMPL(x, y) #define SKULLC_CONCAT(x, y) SKULLC_CONCAT_IMPL(x, y)
#define SKULLC_TAG struct SKULLC_CONCAT(SkullCTag_, __COUNTER__) #define SKULLC_TAG struct SKULLC_CONCAT(SkullCTag_, __COUNTER__)
#endif// SKULLC_UTILITY_TAG_HPP_ #endif // SKULLC_UTILITY_TAG_HPP_

View File

@ -19,15 +19,18 @@ namespace Utility::Assert
namespace Detail namespace Detail
{ {
void assertImpl(const char* expression, const char* file, const int line) void assertImpl(const bool expr, const char* file, const int line)
{ {
if (INSTALLED_HANDLER) if (!expr)
INSTALLED_HANDLER(expression, file, line); {
else if (INSTALLED_HANDLER)
std::terminate(); INSTALLED_HANDLER(file, line);
else
std::terminate();
}
} }
}// namespace Detail }
void setHandler(assert_cb callback) void setHandler(assert_cb callback)
{ {
@ -39,4 +42,4 @@ assert_cb getHandler()
return INSTALLED_HANDLER; return INSTALLED_HANDLER;
} }
}// namespace Utility::Assert }