Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions cth/incl/cth/constants.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,12 @@
#define CTH_DEBUG_INLINE_IMPL(code) { code }

#define CTH_RELEASE_NOEXCEPT noexcept(false)
#define CTH_RELEASE_CONSTEXPR
#else
#define CTH_DEBUG_IMPL = default;
#define CTH_DEBUG_INLINE_IMPL(code) \
{}

#define CTH_RELEASE_NOEXCEPT noexcept(true)
#define CTH_RELEASE_CONSTEXPR constexpr
#endif
#include <cstdint>

Expand Down
4 changes: 2 additions & 2 deletions cth/incl/cth/ptr/not_null.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,12 @@ class not_null {
static constexpr bool NOEXCEPT_CHECK_VAL = COMPILATION_MODE != CompilationMode::DEBUG;
static constexpr bool RELEASE_VAL_NOEXCEPT = NOEXCEPT_ASSIGN && NOEXCEPT_MOVE_CTOR;

static CTH_RELEASE_CONSTEXPR void checkVal(T const& obj) noexcept(NOEXCEPT_CHECK_VAL) {
static constexpr void checkVal(T const& obj) noexcept(NOEXCEPT_CHECK_VAL) {
CTH_CRITICAL(obj == Null, "obj must not be Null") {}
}

public:
CTH_RELEASE_CONSTEXPR not_null(T obj) noexcept(NOEXCEPT_MOVE_CTOR && NOEXCEPT_CHECK_VAL) :
constexpr not_null(T obj) noexcept(NOEXCEPT_MOVE_CTOR && NOEXCEPT_CHECK_VAL) :
_obj{std::move(obj)} { not_null::checkVal(_obj); }

template<class U> requires(std::convertible_to<U, T> && !std::same_as<U, T>)
Expand Down
8 changes: 8 additions & 0 deletions cth/tests/src/pointers/not_null_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,14 @@ struct TestStruct {
auto const data = std::make_unique<TestStruct>(EXAMPLE_NUMBER); // NOLINT(cert-err58-cpp)


CTH_TEST(not_null, constexpr) {
static_assert([] {
not_null<int const*> const ptr{&EXAMPLE_NUMBER};
not_null<int const*> const copy{ptr};
return *copy;
}() == EXAMPLE_NUMBER);
}

CTH_TEST(not_null, comparison) {
int a = EXAMPLE_NUMBER;
int b = EXAMPLE_NUMBER;
Expand Down
Loading