Skip to content

Commit 7de7c89

Browse files
committed
🐛 Fix macro semicolon handling
Problem: - GCC and clang differ regarding where they allow `_Pragma`, resulting in clumsy handling of semicolons. Solution: - Use a "null statement" (`static_assert(true)`) in the macro(s) so that neither GCC nor clang complains about extra semicolons.
1 parent 043a765 commit 7de7c89

File tree

1 file changed

+6
-12
lines changed

1 file changed

+6
-12
lines changed

include/log/env.hpp

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,6 @@ using cib_log_env_t = stdx::env<>;
77

88
// NOLINTBEGIN(cppcoreguidelines-macro-usage)
99

10-
#ifdef __clang__
11-
#define CIB_PRAGMA_SEMI
12-
#else
13-
#define CIB_PRAGMA_SEMI ;
14-
#endif
15-
1610
#define CIB_LOG_ENV_DECL(...) \
1711
[[maybe_unused]] typedef decltype([] { \
1812
return stdx::extend_env_t<cib_log_env_t, __VA_ARGS__>{}; \
@@ -26,16 +20,16 @@ using cib_log_env_t = stdx::env<>;
2620
#define CIB_LOG_ENV(...) \
2721
STDX_PRAGMA(diagnostic push) \
2822
STDX_PRAGMA(diagnostic ignored "-Wshadow") \
29-
CIB_LOG_ENV_DECL(__VA_ARGS__) \
30-
CIB_PRAGMA_SEMI \
31-
STDX_PRAGMA(diagnostic pop)
23+
CIB_LOG_ENV_DECL(__VA_ARGS__); \
24+
STDX_PRAGMA(diagnostic pop) \
25+
static_assert(true)
3226

3327
#define CIB_APPEND_LOG_ENV(E) \
3428
STDX_PRAGMA(diagnostic push) \
3529
STDX_PRAGMA(diagnostic ignored "-Wshadow") \
36-
CIB_APPEND_LOG_ENV_DECL(E) \
37-
CIB_PRAGMA_SEMI \
38-
STDX_PRAGMA(diagnostic pop)
30+
CIB_APPEND_LOG_ENV_DECL(E); \
31+
STDX_PRAGMA(diagnostic pop) \
32+
static_assert(true)
3933

4034
#define CIB_WITH_LOG_ENV(...) \
4135
STDX_PRAGMA(diagnostic push) \

0 commit comments

Comments
 (0)