[PATCH] assert: Support assert as variadic macro for C++26 [PR27276]
Tomasz Kaminski
tkaminsk@redhat.com
Thu Feb 5 15:48:16 GMT 2026
On Thu, Feb 5, 2026 at 4:40 PM Tomasz Kaminski <tkaminsk@redhat.com> wrote:
>
>
> On Thu, Feb 5, 2026 at 4:36 PM Florian Weimer <fweimer@redhat.com> wrote:
>
>> * Tomasz Kamiński:
>>
>> > +# if __ASSERT_VARIADIC
>> > +# define assert(...)
>> \
>> > + ((__VA_ARGS__) \
>> > + ? (void)(1 ? 1 : bool(__VA_ARGS__)) \
>> > + : __assert_fail (#__VA_ARGS__, __ASSERT_FILE, __ASSERT_LINE, \
>> > + __ASSERT_FUNCTION))
>>
>> Doesn't this evaluate __VA_ARGS__ multiple times?
>>
> I got the same question initially when I saw this solution, but
> the second bool(__VA_ARGS) is in the false branch of the ternary:
> 1 ? 1 : bool(__VA_ARGS__)
> So it is never evaluated.
>
I will add following in do_test in test-assert-c++.cc, as there seem to be
no
check for lack of double evaluation:
diff --git a/assert/tst-assert-c++.cc b/assert/tst-assert-c++.cc
index 7fb8bbfe26..534a191fbd 100644
--- a/assert/tst-assert-c++.cc
+++ b/assert/tst-assert-c++.cc
@@ -90,6 +90,13 @@ do_test ()
// assert(E::e1);
}
+ {
+ int i = 0;
+ assert(++i);
+ if (i != 1)
+ return 1;
+ }
+
return 0;
}
#define NDEBU
>
>
>>
>> Thanks,
>> Florian
>>
>>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://sourceware.org/pipermail/libc-alpha/attachments/20260205/8eee34d1/attachment-0001.htm>
More information about the Libc-alpha
mailing list