Skip to content

Commit 5bec6e6

Browse files
committed
🐛 Fix STATIC_ASSERT in non-local context
Problem: - The lambda used in `STATIC_ASSERT` has a default capture spec, which is not allowed in non-local contexts. Solution: - Remove the capture spec. It's not needed.
1 parent 0d77b76 commit 5bec6e6

File tree

3 files changed

+6
-2
lines changed

3 files changed

+6
-2
lines changed

include/stdx/static_assert.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ template <bool B> constexpr auto ct_check = ct_check_t<B>{};
3131

3232
// NOLINTNEXTLINE(cppcoreguidelines-macro-usage)
3333
#define STATIC_ASSERT(cond, ...) \
34-
[&]<bool B>() -> bool { \
34+
[]<bool B>() -> bool { \
3535
STDX_PRAGMA(diagnostic push) \
3636
STDX_PRAGMA(diagnostic ignored "-Wunknown-warning-option") \
3737
STDX_PRAGMA(diagnostic ignored "-Wc++26-extensions") \
@@ -45,7 +45,7 @@ template <bool B> constexpr auto ct_check = ct_check_t<B>{};
4545

4646
// NOLINTNEXTLINE(cppcoreguidelines-macro-usage)
4747
#define STATIC_ASSERT(cond, ...) \
48-
[&]<bool B>() -> bool { \
48+
[]<bool B>() -> bool { \
4949
constexpr auto S = STDX_CT_FORMAT(__VA_ARGS__); \
5050
stdx::detail::ct_check<B>.template emit<S>(); \
5151
return B; \

test/fail/static_assert.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
constexpr auto msg =
66
stdx::ct_string{"01234567890123456789012345678901234567890123456789"};
77

8+
static_assert(STATIC_ASSERT(true, "not emitted"));
9+
810
auto main() -> int {
911
static_assert(STATIC_ASSERT(true, "not emitted"));
1012
STATIC_ASSERT(false, msg);

test/fail/static_assert_format.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33

44
// EXPECT: hello world int 123
55

6+
static_assert(STATIC_ASSERT(true, "hello {} {} {}", "world", int, 42));
7+
68
template <typename T> constexpr auto f() {
79
STATIC_ASSERT(false, "hello {} {} {}", "world", T, 123);
810
}

0 commit comments

Comments
 (0)