[PATCH v7] assert: Support assert as variadic macro for C++26 [PR27276]
Adhemerval Zanella Netto
adhemerval.zanella@linaro.org
Tue Mar 3 12:49:21 GMT 2026
On 03/03/26 09:45, Tomasz Kaminski wrote:
>
>
> On Tue, Mar 3, 2026 at 1:39 PM Adhemerval Zanella Netto <adhemerval.zanella@linaro.org <mailto:adhemerval.zanella@linaro.org>> wrote:
>
>
>
> On 03/03/26 07:56, Yury Khrustalev wrote:
> > On Wed, Feb 25, 2026 at 03:01:23PM +0100, Tomasz Kamiński wrote:
> >> From: Jonathan Wakely <jwakely@redhat.com <mailto:jwakely@redhat.com>>
> >
> > This patch has a new test that fails to compile with GCC 14.2 (although
> > it works with GCC 14.3) and causes make check to fail e.g. on Debian 13.
> >
> >> ...
> >>
> >> diff --git a/assert/test-assert-c++-variadic.cc b/assert/test-assert-c++-variadic.cc
> >> new file mode 100644
> >> index 0000000000..1bb8eeb525
> >> --- /dev/null
> >>
> >> ...
> >>
> >> +template <typename Ts>
> >> +constexpr bool
> >> +assert_works ()
> >> +{
> >> + return requires (Ts ts) {
> >> + assert (ts);
> >> + };
> >> +}
> >> +
> >> +enum OE { oe };
> >> +enum TE : int { te };
> >> +enum class SE : int { se };
> >> +
> >> +static_assert ( assert_works <OE> ());
> >> +static_assert ( assert_works <TE> ());
> >
> > These static asserts fail:
> >
> > test-assert-c++-variadic.cc:81:35: error: static assertion failed
> > 81 | static_assert ( assert_works <OE> ());
> > | ~~~~~~~~~~~~~~~~~~^~
> > test-assert-c++-variadic.cc:82:35: error: static assertion failed
> > 82 | static_assert ( assert_works <TE> ())
> >
> > Also:
> >
> > in ‘constexpr’ expansion of ‘assert_works<OE>()’
> > error: ‘constexpr’ call flows off the end of the function
> >
> > Looks like
> >
> > #if defined __cplusplus && __cplusplus > 202302L
> >
> > is not enough to check if this test is supported or not. XFAIL will not
> > help here because the test doesn't compile which causes make check to
> > fail.
>
> It does seems to me this is a compiler bug, I checked with gcc version 14.3.1 20250814
> and gcc version 15.2.1 20260112 without issues.
>
> Tomasz, is this a compiler bug or something has changes for gcc 14? If so
> I think we might need __GNUC_PREREQ for the test.
>
> Yes, this looks like compiler bug that was fixed in 14.3 and 15, but wasn't able to identify
> the specific change yet. I agree that we need a __GNUC_PREREQ for the snippet
> in question, so around these lines:
>
> +#if __GNUC_PREREQ (14, 2)
Shouldn't it be __GNUC_PREREQ (14, 3) ?
> template <typename Ts>
> constexpr bool
> assert_works ()
> {
> return requires (Ts ts) {
> assert (ts);
> };
> }
>
> enum OE { oe };
> enum TE : int { te };
> enum class SE : int { se };
>
> static_assert ( assert_works <OE> ());
> static_assert ( assert_works <TE> ());
> static_assert (!assert_works <SE> ());
> +#endif
>
> Let me know if I should prepare a patch with above change?
Please also add the PR that fixes on a comment for the __GNUC_PREREQ usage.
More information about the Libc-alpha
mailing list