From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from esa4.mentor.iphmx.com (esa4.mentor.iphmx.com [68.232.137.252]) by sourceware.org (Postfix) with ESMTPS id 34C683882076 for ; Tue, 28 Nov 2023 17:08:41 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 34C683882076 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=codesourcery.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=mentor.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 34C683882076 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=68.232.137.252 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1701191325; cv=none; b=rTvHjg8hykTC59le/d+UNyYeSP/kZIhqtk9t8R0Hh2eHIF6yGbpoUOSPexEgjwCBEc26hieoZraKbB0foqDtrMpHZVEdcBzJpDLsIRsiv/L3uQEA4FKscBl7hisu2ZfXwoxnuBLkY3aUYGS6R9lNtiuTnN+a/BjrP81Ksg67qLc= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1701191325; c=relaxed/simple; bh=h1wSKKM9jqTE2oayswQmJBSPhUQlfrXmhe9DE1goPQw=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=suZCFeek1hlPEETJh/pU7CXp/AyCzg+lwWndk1YmVTWDCCpcMlGwsP7V5nqcsmDv4Mnu7pYMgRFScN9n+Kf1pDiDKXmGbrJlmgL+2BjKW34qXKQbx65yHVTwPD3veahJhkMoCHB5MozyQ+XdcDHketvyx5R9nsH1ad0uJvZUulw= ARC-Authentication-Results: i=1; server2.sourceware.org X-CSE-ConnectionGUID: DuVRGoV3RguKdh3mSgn16w== X-CSE-MsgGUID: HqXum9l0RqOnIoUc+baTtg== X-IronPort-AV: E=Sophos;i="6.04,234,1695715200"; d="scan'208,223";a="23906301" Received: from orw-gwy-02-in.mentorg.com ([192.94.38.167]) by esa4.mentor.iphmx.com with ESMTP; 28 Nov 2023 09:08:39 -0800 IronPort-SDR: Hu1F6RgF1JNMeaAlPY6PvWN9OqyeTMEwUHOTejqyHAK3V209+vDHXJxtoao+x66BUaP4YlU/e5 1tf3OrlRQyyaf7uf2s4V/qk9D64761pd4gSuxmTUmeiytTVA1cCTz/+7yF6GsEW4y0eLYbazxI iSu+hwIbLBD6NSat4lYiXzaNCIVJlOg3L4ICqy9ew9wwB3vWeCLpHDUrLOsrYjlmK/QQWJfnDk 8R0mUbKUKCi6+goTfQPAqDj6BikghiNp3X+MIJahNooxCg9dwAb5HqImV7MmNKQ5jVSPrEuE/o ZN4= From: Thomas Schwinge To: Jakub Jelinek , Jason Merrill , Subject: Fix 'g++.dg/cpp26/static_assert1.C' for '-fno-exceptions' configurations (was: [PATCH] c++, v4: Implement C++26 P2741R3 - user-generated static_assert messages [PR110348]) In-Reply-To: References: <4b133eec-f806-43af-800a-8339d50645fd@redhat.com> <79a9ad09-2feb-4f3b-a4fe-1d13293fcd8b@redhat.com> User-Agent: Notmuch/0.29.3+94~g74c3f1b (https://notmuchmail.org) Emacs/28.2 (x86_64-pc-linux-gnu) Date: Tue, 28 Nov 2023 18:08:33 +0100 Message-ID: <87sf4p6c1a.fsf@euler.schwinge.homeip.net> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" X-Originating-IP: [137.202.0.90] X-ClientProxiedBy: svr-ies-mbx-11.mgc.mentorg.com (139.181.222.11) To svr-ies-mbx-10.mgc.mentorg.com (139.181.222.10) X-Spam-Status: No, score=-11.8 required=5.0 tests=BAYES_00,GIT_PATCH_0,HEADER_FROM_DIFFERENT_DOMAINS,KAM_DMARC_STATUS,SPF_HELO_PASS,SPF_PASS,TXREP,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: --=-=-= Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Hi! On 2023-11-23T09:32:24+0100, Jakub Jelinek wrote: > Here is what I've committed > --- gcc/testsuite/g++.dg/cpp26/static_assert1.C.jj 2023-11-22 10:17:41= .340064988 +0100 > +++ gcc/testsuite/g++.dg/cpp26/static_assert1.C 2023-11-22 10:47:45= .045848504 +0100 > @@ -0,0 +1,309 @@ > +// C++26 P2741R3 - user-generated static_assert messages OK to push the attached "Fix 'g++.dg/cpp26/static_assert1.C' for '-fno-exceptions' configurations"? Gr=C3=BC=C3=9Fe Thomas > +// { dg-do compile { target c++11 } } > +// { dg-options "" } > + > +static_assert (true, ""); > +static_assert (true, ("")); // { dg-warning "'static_assert' with non-s= tring message only available with" "" { target c++23_down } } > + // { dg-error "'static_assert' message must= be a string literal or object with 'size' and 'data' members" "" { target = *-*-* } .-1 } > + // { dg-error "request for member 'size' in= '\\\(\\\"\\\"\\\)', which is of non-class type 'const char \\\[1\\\]'" "" = { target *-*-* } .-2 } > +static_assert (true, "" + 0); // { dg-warning "'static_assert' wi= th non-string message only available with" "" { target c++23_down } } > + // { dg-error "'static_assert' message must= be a string literal or object with 'size' and 'data' members" "" { target = *-*-* } .-1 } > + // { dg-error "request for member 'size' in= '\\\(const char\\\*\\\)\\\"\\\"', which is of non-class type 'const char\\= \*'" "" { target *-*-* } .-2 } > +static_assert (true, 0); // { dg-warning "'static_assert' with non-s= tring message only available with" "" { target c++23_down } } > + // { dg-error "'static_assert' message must= be a string literal or object with 'size' and 'data' members" "" { target = *-*-* } .-1 } > + // { dg-error "request for member 'size' in= '0', which is of non-class type 'int'" "" { target *-*-* } .-2 } > +struct A {}; > +static_assert (true, A {}); // { dg-warning "'static_assert' with non-s= tring message only available with" "" { target c++23_down } } > + // { dg-error "'static_assert' message must= be a string literal or object with 'size' and 'data' members" "" { target = *-*-* } .-1 } > + // { dg-error "'struct A' has no member nam= ed 'size'" "" { target *-*-* } .-2 } > +struct B { int size; }; > +static_assert (true, B {}); // { dg-warning "'static_assert' with non-s= tring message only available with" "" { target c++23_down } } > + // { dg-error "'static_assert' message must= be a string literal or object with 'size' and 'data' members" "" { target = *-*-* } .-1 } > + // { dg-error "'struct B' has no member nam= ed 'data'" "" { target *-*-* } .-2 } > +struct C { constexpr int size () const { return 0; } }; > +static_assert (true, C {}); // { dg-warning "'static_assert' with non-s= tring message only available with" "" { target c++23_down } } > + // { dg-error "'static_assert' message must= be a string literal or object with 'size' and 'data' members" "" { target = *-*-* } .-1 } > + // { dg-error "'struct C' has no member nam= ed 'data'" "" { target *-*-* } .-2 } > +struct D { constexpr int size () const { return 0; } int data; }; > +static_assert (true, D {}); // { dg-warning "'static_assert' with non-s= tring message only available with" "" { target c++23_down } } > + // { dg-error "'D\\\(\\\).D::data' cannot b= e used as a function" "" { target *-*-* } .-1 } > +struct E { int size =3D 0; > + constexpr const char *data () const { return ""; } }; > +static_assert (true, E {}); // { dg-warning "'static_assert' with non-s= tring message only available with" "" { target c++23_down } } > + // { dg-error "'E\\\(\\\).E::size' cannot b= e used as a function" "" { target c++11_only } .-1 } > + // { dg-error "'E\\\{0\\\}.E::size' cannot = be used as a function" "" { target c++14 } .-2 } > +struct F { constexpr const char *size () const { return ""; } > + constexpr const char *data () const { return ""; } }; > +static_assert (true, F {}); // { dg-warning "'static_assert' with non-s= tring message only available with" "" { target c++23_down } } > + // { dg-error "'static_assert' message 'siz= e\\\(\\\)' must be implicitly convertible to 'std::size_t'" "" { target *-*= -* } .-1 } > + // { dg-error "could not convert 'F\\\(\\\)= .F::size\\\(\\\)' from 'const char\\\*' to '\[^']*'" "" { target *-*-* } .-= 2 } > + // { dg-error "conversion from 'const char\= \\*' to '\[^']*' in a converted constant expression" "" { target *-*-* } .-= 3 } > +struct G { constexpr long size () const { return 0; } > + constexpr float data () const { return 0.0f; } }; > +static_assert (true, G {}); // { dg-warning "'static_assert' with non-s= tring message only available with" "" { target c++23_down } } > + // { dg-error "'static_assert' message 'dat= a\\\(\\\)' must be implicitly convertible to 'const char\\\*'" "" { target = *-*-* } .-1 } > + // { dg-error "could not convert 'G\\\(\\\)= .G::data\\\(\\\)' from 'float' to 'const char\\\*'" "" { target *-*-* } .-2= } > +struct H { short size () const { return 0; } > + constexpr const char *data () const { return ""; } }; > +static_assert (true, H {}); // { dg-warning "'static_assert' with non-s= tring message only available with" "" { target c++23_down } } > +struct I { constexpr signed char size () const { return 0; } > + const char *data () const { return ""; } }; > +static_assert (true, I {}); // { dg-warning "'static_assert' with non-s= tring message only available with" "" { target c++23_down } } > +struct J { constexpr int size () const { return j ? throw 1 : 0; } // = { dg-error "expression '' is not a constant expression" } > + constexpr const char *data () const { return ""; }; > + constexpr J (int x) : j (x) {} > + int j; }; > +static_assert (true, J (1)); // { dg-warning "'static_assert' with non-s= tring message only available with" "" { target c++23_down } } > +static_assert (false, J (0)); // { dg-warning "'static_assert' wi= th non-string message only available with" "" { target c++23_down } } > + // { dg-error "static assertion failed" "" = { target *-*-* } .-1 } > +static_assert (false, J (1)); // { dg-warning "'static_assert' wi= th non-string message only available with" "" { target c++23_down } } > + // { dg-error "'static_assert' message 'siz= e\\\(\\\)' must be a constant expression" "" { target *-*-* } .-1 } > +struct K { constexpr operator int () { return 4; } }; > +struct L { constexpr operator const char * () { return "test"; } }; > +struct M { constexpr K size () const { return {}; } > + constexpr L data () const { return {}; } }; > +static_assert (true, M {}); // { dg-warning "'static_assert' with non-s= tring message only available with" "" { target c++23_down } } > +static_assert (false, M {}); // { dg-warning "'static_assert' with non-s= tring message only available with" "" { target c++23_down } } > + // { dg-error "static assertion failed: tes= t" "" { target *-*-* } .-1 } > +#if __cpp_constexpr_dynamic_alloc >=3D 201907L > +struct N { constexpr int size () const { return 3; } > + constexpr const char *data () const { return new char[3] { 'b', = 'a', 'd' }; } }; // { dg-error "'\\\* N\\\(\\\).N::data\\\(\\\)' is not a c= onstant expression because allocated storage has not been deallocated" "" {= target c++20 } } > +static_assert (true, N {}); // { dg-warning "'static_assert' with non-s= tring message only available with" "" { target { c++20 && c++23_down } } } > +static_assert (false, N {}); // { dg-warning "'static_assert' with non-s= tring message only available with" "" { target { c++20 && c++23_down } } } > + // { dg-error "'static_assert' message 'dat= a\\\(\\\)\\\[0\\\]' must be a constant expression" "" { target c++20 } .-1 = } > +#endif > +constexpr const char a[] =3D { 't', 'e', 's', 't' }; > +struct O { constexpr int size () const { return 4; } > + constexpr const char *data () const { return a; } }; > +static_assert (false, O {}); // { dg-warning "'static_assert' with non-s= tring message only available with" "" { target c++23_down } } > + // { dg-error "static assertion failed: tes= t" "" { target *-*-* } .-1 } > +struct P { constexpr int size () const { return 4 - p; } > + constexpr const char *data () const { return &a[p]; } > + constexpr P (int x) : p (x) {} > + int p; }; > +static_assert (false, P (0)); // { dg-warning "'static_assert' wi= th non-string message only available with" "" { target c++23_down } } > + // { dg-error "static assertion failed: tes= t" "" { target *-*-* } .-1 } > +static_assert (false, P (2)); // { dg-warning "'static_assert' wi= th non-string message only available with" "" { target c++23_down } } > + // { dg-error "static assertion failed: st"= "" { target *-*-* } .-1 } > +struct Q { constexpr int size () const { return 4 - q; } > + constexpr const char *data () const { return &"test"[q]; } > + constexpr Q (int x) : q (x) {} > + int q; }; > +static_assert (false, Q (0)); // { dg-warning "'static_assert' wi= th non-string message only available with" "" { target c++23_down } } > + // { dg-error "static assertion failed: tes= t" "" { target *-*-* } .-1 } > +static_assert (false, Q (1)); // { dg-warning "'static_assert' wi= th non-string message only available with" "" { target c++23_down } } > + // { dg-error "static assertion failed: est= " "" { target *-*-* } .-1 } > +struct R { constexpr int size () const { return 4 - r; } > + constexpr const char *d () const { return "test"; } > + constexpr const char *data () const { return d () + r; } > + constexpr R (int x) : r (x) {} > + int r; }; > +static_assert (false, R (0)); // { dg-warning "'static_assert' wi= th non-string message only available with" "" { target c++23_down } } > + // { dg-error "static assertion failed: tes= t" "" { target *-*-* } .-1 } > +static_assert (false, R (2)); // { dg-warning "'static_assert' wi= th non-string message only available with" "" { target c++23_down } } > + // { dg-error "static assertion failed: st"= "" { target *-*-* } .-1 } > +struct S { constexpr float size (float) const { return 42.0f; } > + constexpr int size (void * =3D nullptr) const { return 4; } > + constexpr double data (double) const { return 42.0; } > + constexpr const char *data (int =3D 0) const { return "test"; } = }; > +static_assert (true, S {}); // { dg-warning "'static_assert' with non-s= tring message only available with" "" { target c++23_down } } > +static_assert (false, S {}); // { dg-warning "'static_assert' with non-s= tring message only available with" "" { target c++23_down } } > + // { dg-error "static assertion failed: tes= t" "" { target *-*-* } .-1 } > + > +using size_t =3D decltype (sizeof (0)); > +struct string_view { > + size_t s; > + const char *d; > + constexpr string_view () : s (0), d (nullptr) {} > + constexpr string_view (const char *p) : s (__builtin_strlen (p)), d (p= ) {} > + constexpr string_view (size_t l, const char *p) : s (l), d (p) {} > + constexpr size_t size () const noexcept { return s; } > + constexpr const char *data () const noexcept { return d; } > +}; > +static_assert (true, string_view{}); // { dg-war= ning "'static_assert' with non-string message only available with" "" { tar= get c++23_down } } > +static_assert (false, string_view ("test")); // { dg-war= ning "'static_assert' with non-string message only available with" "" { tar= get c++23_down } } > + // { dg-err= or "static assertion failed: test" "" { target *-*-* } .-1 } > +static_assert (false, string_view ("=D7=90")); // { d= g-warning "'static_assert' with non-string message only available with" "" = { target c++23_down } } > + // { dg-err= or "static assertion failed: =D7=90" "" { target *-*-* } .-1 } > +static_assert (false, string_view (0, nullptr)); // { dg-war= ning "'static_assert' with non-string message only available with" "" { tar= get c++23_down } } > + // { dg-err= or "static assertion failed" "" { target *-*-* } .-1 } > +static_assert (false, string_view (4, "testwithextrachars")); // = { dg-warning "'static_assert' with non-string message only available with" = "" { target c++23_down } } > + // { dg-err= or "static assertion failed: test" "" { target *-*-* } .-1 } > +static_assert (false, string_view (42, "test")); // { dg-war= ning "'static_assert' with non-string message only available with" "" { tar= get c++23_down } } > + // { dg-err= or "array subscript value '41' is outside the bounds of array type 'const c= har \\\[5\\\]'" "" { target *-*-* } .-1 } > + // { dg-err= or "'static_assert' message 'data\\\(\\\)\\\[41\\\]' must be a constant exp= ression" "" { target *-*-* } .-2 } > + > +template > +struct array { > + constexpr size_t size () const { return N; } > + constexpr const T *data () const { return a; } > + const T a[N]; > +}; > +static_assert (true, array { 'O', 'K' }); // { dg-war= ning "'static_assert' with non-string message only available with" "" { tar= get c++23_down } } > +static_assert (true, array { L'O', L'K' }); // = { dg-warning "'static_assert' with non-string message only available with" = "" { target c++23_down } } > + // { dg-err= or "'static_assert' message 'data\\\(\\\)' must be implicitly convertible t= o 'const char\\\*'" "" { target *-*-* } .-1 } > + // { dg-err= or "could not convert 'array{const wchar_t \\\[2\\\]{\[0-9]+, \= [0-9]+}}.array::data\\\(\\\)' from 'const wchar_t\\\*' to 'cons= t char\\\*'" "" { target *-*-* } .-2 } > +static_assert (false, array { 't', 'e', 's', 't' }); // = { dg-warning "'static_assert' with non-string message only available with" = "" { target c++23_down } } > + // { dg-err= or "static assertion failed: test" "" { target *-*-* } .-1 } > + > +void > +foo () > +{ > + constexpr auto a =3D array { 't', 'e', 's', 't' }; > + static_assert (false, a); // { dg-war= ning "'static_assert' with non-string message only available with" "" { tar= get c++23_down } } > +} // { dg-err= or "static assertion failed: test" "" { target *-*-* } .-1 } > + > +#if __cpp_constexpr_dynamic_alloc >=3D 201907L > +struct T { > + const char *d =3D init (); > + constexpr int size () const { return 4; } > + constexpr const char *data () const { return d; } > + constexpr const char *init () const { return new char[4] { 't', 'e', '= s', 't' }; } > + constexpr ~T () { delete[] d; } > +}; > +static_assert (false, T{}); // { dg-warning "'static_assert' wi= th non-string message only available with" "" { target { c++20 && c++23_dow= n } } } > + // { dg-error "static assertion fai= led: test" "" { target c++20 } .-1 } > +#endif > +struct U { constexpr operator const char * () const { return u; } > + char u[5] =3D "test"; }; > +#if __cplusplus >=3D 201402L > +struct V { constexpr auto size () const { return K{}; } > + constexpr auto data () const { return U{}; } }; > +static_assert (false, V{}); // { dg-warning "'static_assert' wi= th non-string message only available with" "" { target { c++14 && c++23_dow= n } } } > + // { dg-error "static assertion fai= led: test" "" { target c++14 } .-1 } > +#endif > +struct W { constexpr int size (int) const { return 4; } > + constexpr const char *data () const { return "test"; } }; > +static_assert (true, W{}); // { dg-warning "'static_assert' wi= th non-string message only available with" "" { target c++23_down } } > + // { dg-error "no matching function= for call to 'W::size\\\(\\\)'" "" { target *-*-* } .-1 } > +struct X { constexpr int size () const { return 4; } > + constexpr const char *data (int) const { return "test"; } }; > +static_assert (true, X{}); // { dg-warning "'static_assert' wi= th non-string message only available with" "" { target c++23_down } } > + // { dg-error "no matching function= for call to 'X::data\\\(\\\)'" "" { target *-*-* } .-1 } > +struct Y { constexpr int size () { return 4; } > + constexpr const char *data (int) { return "test"; } }; > +static_assert (true, Y{}); // { dg-warning "'static_assert' wi= th non-string message only available with" "" { target c++23_down } } > + // { dg-error "no matching function= for call to 'Y::data\\\(\\\)'" "" { target *-*-* } .-1 } > +#if __cpp_concepts >=3D 201907L > +struct Z { constexpr int size (auto...) const { return 4; } > + constexpr const char *data (auto...) const { return "test"; } }; > +static_assert (false, Z{}); // { dg-warning "'static_assert' wi= th non-string message only available with" "" { target { c++20 && c++23_dow= n } } } > + // { dg-error "static assertion fai= led: test" "" { target c++20 } .-1 } > +#endif > + > +namespace NN > +{ > + template > + struct A { > + constexpr int size () const =3D delete; > + constexpr const char *data () const { return "test"; } }; > + static_assert (true, A{}); // { dg-warning "'static_assert' wi= th non-string message only available with" "" { target c++23_down } } > + // { dg-error "use of deleted funct= ion 'constexpr int NN::A::size\\\(\\\) const \\\[with T =3D int\\\]'" ""= { target *-*-* } .-1 } > +#if __cpp_concepts >=3D 201907L > + template > + struct B { > + constexpr int size () const { return 4; } > + constexpr const char *data () const requires false { return "test"; = } }; > + static_assert (true, B{}); // { dg-warning "'static_assert' wi= th non-string message only available with" "" { target { c++20 && c++23_dow= n } } } > + // { dg-error "no matching function= for call to 'NN::B::data\\\(\\\)'" "" { target c++20 } .-1 } > +#endif > + class C { > + constexpr int size () const =3D delete; > + constexpr const char *data () const { return "test"; } }; > + static_assert (true, C{}); // { dg-warning "'static_assert' wi= th non-string message only available with" "" { target c++23_down } } > + // { dg-error "use of deleted funct= ion 'constexpr int NN::C::size\\\(\\\) const'" "" { target *-*-* } .-1 } > + // { dg-error "'constexpr const cha= r\\\* NN::C::data\\\(\\\) const' is private within this context" "" { targe= t *-*-* } .-2 } > +#if __cplusplus >=3D 201402L > + struct D { > + constexpr int size () { return 4; } > + constexpr int size () const { return 3; } > + constexpr const char *data () { return "test"; } > + constexpr const char *data () const { return "ehlo"; } }; > + static_assert (true, D{}); // { dg-warning "'static_assert' with non-s= tring message only available with" "" { target { c++14 && c++23_down } } } > + static_assert (false, D{}); // { dg-warning "'static_assert' wi= th non-string message only available with" "" { target { c++14 && c++23_dow= n } } } > + // { dg-error "static assertion failed: tes= t" "" { target c++14 } .-1 } > +#endif > + struct E { > + constexpr int size () const { return 4; } > + constexpr const char *data () const { return "test"; } }; > + template > + struct F { > + static_assert (false, T{}); // { dg-warning "'static_assert' wi= th non-string message only available with" "" { target c++23_down } } > + }; // { dg-error "static assertion failed: tes= t" "" { target *-*-* } .-1 } > + template > + struct G { > + static_assert (false, T{}); // { dg-warning "'static_assert' wi= th non-string message only available with" "" { target c++23_down } } > + }; // { dg-error "'static_assert' message must= be a string literal or object with 'size' and 'data' members" "" { target = *-*-* } .-1 } > + // { dg-error "request for member 'size' in= '0', which is of non-class type 'long int'" "" { target *-*-* } .-2 } > + F fe; > + G gl; > + constexpr E operator ""_myd (const char *, size_t) { return E{}; } > + static_assert (false, "foo"_myd); // { dg-warning "'static_assert' wi= th non-string message only available with" "" { target c++23_down } } > + // { dg-error "static assertion fai= led: test" "" { target *-*-* } .-1 } > + constexpr E operator + (const char *, const E &) { return E{}; } > + static_assert (false, "foo" + E{}); // { dg-warning "'static_as= sert' with non-string message only available with" "" { target c++23_down }= } > + // { dg-error "static assertion fai= led: test" "" { target *-*-* } .-1 } > + struct H { > + static constexpr int size () { return 7; } > + static constexpr const char *data () { return "message"; } }; > + static_assert (true, H{}); // { dg-warning "'static_assert' wi= th non-string message only available with" "" { target c++23_down } } > + static_assert (false, H{}); // { dg-warning "'static_as= sert' with non-string message only available with" "" { target c++23_down }= } > + // { dg-error "static assertion fai= led: message" "" { target *-*-* } .-1 } > + struct I { > + static constexpr int size () { return 0; } > + static constexpr const char *data () { return nullptr; } }; > + static_assert (true, I{}); // { dg-warning "'static_assert' wi= th non-string message only available with" "" { target c++23_down } } > + static_assert (false, I{}); // { dg-warning "'static_as= sert' with non-string message only available with" "" { target c++23_down }= } > + // { dg-error "static assertion fai= led" "" { target *-*-* } .-1 } > +#if __cplusplus >=3D 201402L > + struct J { > + static constexpr int size () { return 0; } > + static constexpr const char *data (int x =3D 0) { if (x) return null= ptr; else throw 1; } }; // { dg-error "expression '' is n= ot a constant expression" "" { target c++14 } } > + static_assert (true, J{}); // { dg-warning "'static_assert' wi= th non-string message only available with" "" { target { c++14 && c++23_dow= n } } } > + static_assert (false, J{}); // { dg-warning "'static_as= sert' with non-string message only available with" "" { target { c++14 && c= ++23_down } } } > + // { dg-error "'static_assert' mess= age 'data\\\(\\\)' must be a core constant expression" "" { target c++14 } = .-1 } > +#endif > +#if __cpp_if_consteval >=3D 202106L > + struct K { > + static constexpr int size () { if consteval { return 4; } else { thr= ow 1; } } > + static constexpr const char *data () { return "test"; } > + }; > + static_assert (true, K{}); // { dg-warning "'static_assert' wi= th non-string message only available with" "" { target c++23_only } } > + static_assert (false, K{}); // { dg-warning "'static_as= sert' with non-string message only available with" "" { target c++23_only }= } > + // { dg-error "static assertion fai= led: test" "" { target c++23 } .-1 } > + struct L { > + static constexpr int size () { return 4; } > + static constexpr const char *data () { if consteval { return "test";= } else { throw 1; } } > + }; > + static_assert (true, L{}); // { dg-warning "'static_assert' wi= th non-string message only available with" "" { target c++23_only } } > + static_assert (false, L{}); // { dg-warning "'static_as= sert' with non-string message only available with" "" { target c++23_only }= } > + // { dg-error "static assertion fai= led: test" "" { target c++23 } .-1 } > + struct M { > + static constexpr int size () { if consteval { throw 1; } else { retu= rn 4; } } // { dg-error "expression '' is not a constant = expression" "" { target c++23 } } > + static constexpr const char *data () { return "test"; } > + }; > + static_assert (true, M{}); // { dg-warning "'static_assert' wi= th non-string message only available with" "" { target c++23_only } } > + static_assert (false, M{}); // { dg-warning "'static_as= sert' with non-string message only available with" "" { target c++23_only }= } > + // { dg-error "'static_assert' mess= age 'size\\\(\\\)' must be a constant expression" "" { target c++23 } .-1 } > + struct N { > + static constexpr int size () { return 4; } > + static constexpr const char *data () { if consteval { throw 1; } els= e { return "test"; } } // { dg-error "expression '' is no= t a constant expression" "" { target c++23 } } > + }; > + static_assert (true, N{}); // { dg-warning "'static_assert' wi= th non-string message only available with" "" { target c++23_only } } > + static_assert (false, N{}); // { dg-warning "'static_as= sert' with non-string message only available with" "" { target c++23_only }= } > + // { dg-error "'static_assert' mess= age 'data\\\(\\\)\\\[0\\\]' must be a constant expression" "" { target c++2= 3 } .-1 } > +#endif > + struct O { constexpr int operator () () const { return 12; } }; > + struct P { constexpr const char *operator () () const { return "anothe= r test"; } }; > + struct Q { O size; P data; }; > + static_assert (true, Q ()); // { dg-warning "'static_assert' wi= th non-string message only available with" "" { target c++23_down } } > + static_assert (false, Q {}); // { dg-warning "'static_assert' wi= th non-string message only available with" "" { target c++23_down } } > + // { dg-error "static assertion failed: ano= ther test" "" { target *-*-* } .-1 } > + constexpr int get_size () { return 16; } > + constexpr const char *get_data () { return "yet another test"; } > + struct R { int (*size) () =3D NN::get_size; > + const char *(*data) () =3D NN::get_data; }; > + static_assert (true, R ()); // { dg-warning "'static_assert' wi= th non-string message only available with" "" { target c++23_down } } > + static_assert (false, R {}); // { dg-warning "'static_assert' wi= th non-string message only available with" "" { target c++23_down } } > + // { dg-error "static assertion failed: yet= another test" "" { target *-*-* } .-1 } > +} ----------------- Siemens Electronic Design Automation GmbH; Anschrift: Arnulfstra=C3=9Fe 201= , 80634 M=C3=BCnchen; Gesellschaft mit beschr=C3=A4nkter Haftung; Gesch=C3= =A4ftsf=C3=BChrer: Thomas Heurung, Frank Th=C3=BCrauf; Sitz der Gesellschaf= t: M=C3=BCnchen; Registergericht M=C3=BCnchen, HRB 106955 --=-=-= Content-Type: text/x-diff Content-Disposition: inline; filename="0001-Fix-g-.dg-cpp26-static_assert1.C-for-fno-exceptions-.patch" >From b93caa5f0680f4c2c3c898373bc561bc54673765 Mon Sep 17 00:00:00 2001 From: Thomas Schwinge Date: Tue, 28 Nov 2023 17:52:34 +0100 Subject: [PATCH] Fix 'g++.dg/cpp26/static_assert1.C' for '-fno-exceptions' configurations This test case, added in recent commit 6ce952188ab39e303e4f63e474b5cba83b5b12fd "c++: Implement C++26 P2741R3 - user-generated static_assert messages [PR110348]", expectedly runs into 'UNSUPPORTED: [...]: exception handling disabled', but along the way also FAILs a few tests: UNSUPPORTED: g++.dg/cpp26/static_assert1.C -std=gnu++98 PASS: g++.dg/cpp26/static_assert1.C -std=gnu++11 (test for warnings, line 6) [...] PASS: g++.dg/cpp26/static_assert1.C -std=gnu++11 (test for warnings, line 51) FAIL: g++.dg/cpp26/static_assert1.C -std=gnu++11 (test for errors, line 52) PASS: g++.dg/cpp26/static_assert1.C -std=gnu++11 (test for warnings, line 56) PASS: g++.dg/cpp26/static_assert1.C -std=gnu++11 (test for warnings, line 57) FAIL: g++.dg/cpp26/static_assert1.C -std=gnu++11 at line 58 (test for errors, line 57) PASS: g++.dg/cpp26/static_assert1.C -std=gnu++11 (test for warnings, line 59) [...] PASS: g++.dg/cpp26/static_assert1.C -std=gnu++11 at line 308 (test for errors, line 307) UNSUPPORTED: g++.dg/cpp26/static_assert1.C -std=gnu++11: exception handling disabled PASS: g++.dg/cpp26/static_assert1.C -std=gnu++14 (test for warnings, line 6) [...] PASS: g++.dg/cpp26/static_assert1.C -std=gnu++14 (test for warnings, line 51) FAIL: g++.dg/cpp26/static_assert1.C -std=gnu++14 (test for errors, line 52) PASS: g++.dg/cpp26/static_assert1.C -std=gnu++14 (test for warnings, line 56) PASS: g++.dg/cpp26/static_assert1.C -std=gnu++14 (test for warnings, line 57) FAIL: g++.dg/cpp26/static_assert1.C -std=gnu++14 at line 58 (test for errors, line 57) PASS: g++.dg/cpp26/static_assert1.C -std=gnu++14 (test for warnings, line 59) [...] PASS: g++.dg/cpp26/static_assert1.C -std=gnu++14 at line 257 (test for errors, line 256) FAIL: g++.dg/cpp26/static_assert1.C -std=gnu++14 (test for errors, line 261) PASS: g++.dg/cpp26/static_assert1.C -std=gnu++14 (test for warnings, line 262) [...] PASS: g++.dg/cpp26/static_assert1.C -std=gnu++14 at line 308 (test for errors, line 307) UNSUPPORTED: g++.dg/cpp26/static_assert1.C -std=gnu++14: exception handling disabled PASS: g++.dg/cpp26/static_assert1.C -std=gnu++20 (test for warnings, line 6) [...] PASS: g++.dg/cpp26/static_assert1.C -std=gnu++20 (test for warnings, line 51) FAIL: g++.dg/cpp26/static_assert1.C -std=gnu++20 (test for errors, line 52) PASS: g++.dg/cpp26/static_assert1.C -std=gnu++20 (test for warnings, line 56) PASS: g++.dg/cpp26/static_assert1.C -std=gnu++20 (test for warnings, line 57) FAIL: g++.dg/cpp26/static_assert1.C -std=gnu++20 at line 58 (test for errors, line 57) PASS: g++.dg/cpp26/static_assert1.C -std=gnu++20 (test for warnings, line 59) [...] PASS: g++.dg/cpp26/static_assert1.C -std=gnu++20 at line 257 (test for errors, line 256) FAIL: g++.dg/cpp26/static_assert1.C -std=gnu++20 (test for errors, line 261) PASS: g++.dg/cpp26/static_assert1.C -std=gnu++20 (test for warnings, line 262) [...] PASS: g++.dg/cpp26/static_assert1.C -std=gnu++20 at line 308 (test for errors, line 307) UNSUPPORTED: g++.dg/cpp26/static_assert1.C -std=gnu++20: exception handling disabled Use an explicit '-fexceptions' to turn this front end test case all-PASS. gcc/testsuite/ * g++.dg/cpp26/static_assert1.C: Fix for '-fno-exceptions' configurations. --- gcc/testsuite/g++.dg/cpp26/static_assert1.C | 2 ++ 1 file changed, 2 insertions(+) diff --git a/gcc/testsuite/g++.dg/cpp26/static_assert1.C b/gcc/testsuite/g++.dg/cpp26/static_assert1.C index 9dec52b90d6..59724ae32ce 100644 --- a/gcc/testsuite/g++.dg/cpp26/static_assert1.C +++ b/gcc/testsuite/g++.dg/cpp26/static_assert1.C @@ -1,6 +1,8 @@ // C++26 P2741R3 - user-generated static_assert messages // { dg-do compile { target c++11 } } // { dg-options "" } +// Override any default-'-fno-exceptions': +// { dg-additional-options -fexceptions } static_assert (true, ""); static_assert (true, ("")); // { dg-warning "'static_assert' with non-string message only available with" "" { target c++23_down } } -- 2.34.1 --=-=-=--