Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added FLUX_ASSERT macro #13

Merged
merged 1 commit into from
May 7, 2024
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
5 changes: 4 additions & 1 deletion flux-config/flux/config.hpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
#pragma once

#include <flux/config/macro.hpp>
#include <flux/config/macro.hpp>

#include <flux/config/assert.hpp>
#include <flux/config/features_support.hpp>
25 changes: 25 additions & 0 deletions flux-config/flux/config/assert.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#pragma once

// clang-format off
#define FLUX_ASSERT_1_ARGS(expression) \
(__builtin_expect(static_cast<bool>(expression), 1) \
? (void)0 \
: ::flux::io::panic(__FILE__ ":" FLUX_TO_STRING(__LINE__) \
": Assertion `" FLUX_TO_STRING(expression) "' failed."))

#define FLUX_ASSERT_2_ARGS(expression, message) \
(__builtin_expect(static_cast<bool>(expression), 1) \
? (void)0 \
: ::flux::io::panic(__FILE__ ":" FLUX_TO_STRING(__LINE__) \
": Assertion `" FLUX_TO_STRING(expression) "' failed: " message "."))
// clang-format on

#define FLUX_ASSERT_GET_3RD_ARG(arg1, arg2, arg3, ...) arg3
#define FLUX_ASSERT_MACRO_CHOOSER(...) \
FLUX_ASSERT_GET_3RD_ARG(__VA_ARGS__, FLUX_ASSERT_2_ARGS, FLUX_ASSERT_1_ARGS, )

#ifdef NDEBUG
# define FLUX_ASSERT(...) ((void)0)
#else
# define FLUX_ASSERT(...) FLUX_ASSERT_MACRO_CHOOSER(__VA_ARGS__)(__VA_ARGS__)
#endif
26 changes: 26 additions & 0 deletions flux-config/flux/config/features_support.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#pragma once

#if __has_cpp_attribute(msvc::no_unique_address)
// MSVC implements [[no_unique_address]] as a silent no-op currently. If/when MSVC breaks its C++
// ABI, it will be changed to work as intended. However, MSVC implements [[msvc::no_unique_address]]
// which does what [[no_unique_address]] is supposed to do, in general.

// Clang-cl does not yet (14.0) implement either [[no_unique_address]] or
// [[msvc::no_unique_address]] though. If/when it does implement [[msvc::no_unique_address]], this
// should be preferred though.
# define FLUX_NO_UNIQUE_ADDRESS [[msvc::no_unique_address]]
#elif __has_cpp_attribute(no_unique_address)
# define FLUX_NO_UNIQUE_ADDRESS [[no_unique_address]]
#else
// Note that this can be replaced by #error as soon as clang-cl implements msvc::no_unique_address,
// since there should be no C++20 compiler that doesn't support one of the two attributes at that
// point. I generally don't want to use this macro outside of C++20-only code, because using it
// conditionally in one language version only would make the ABI inconsistent.
# define FLUX_NO_UNIQUE_ADDRESS /* nothing */
#endif

#if __has_attribute(__no_sanitize__)
# define FLUX_NO_SANITIZE(...) __attribute__((__no_sanitize__(__VA_ARGS__)))
#else
# define FLUX_NO_SANITIZE(...)
#endif
1 change: 0 additions & 1 deletion flux-logging/flux/logging/detail/source_location.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,6 @@ print_reserve_define_source_location_impl(char* it,

inline constexpr flux_source_location_scatter
print_alias_define_source_location_impl(flux::log::source_location location) noexcept {
using flux::log::detail::strip_path;
return {{location.file_name(), cstr_len(location.file_name())},
{location.function_name(), cstr_len(location.function_name())},
location.line(),
Expand Down