From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from cosmopolitan.snafu.de (cosmopolitan.snafu.de [IPv6:2001:1560:3:255::151]) by sourceware.org (Postfix) with ESMTPS id 27D7038582AC; Tue, 8 Aug 2023 16:04:10 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 27D7038582AC Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=berlin.de Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=berlin.de X-Trace: 507c6e696b6f6c61736b6c6175736572406265726c696e2e64657c37332e323331 2e372e3234327c31715450426b2d3030304756642d4b5a7c313639313531303634 34 Received: from cosmopolitan.snafu.de ([10.151.10.49] helo=localhost) by cosmopolitan.snafu.de with esmtpsa (Exim 4.94.2) id 1qTPBk-000GVd-KZ; Tue, 08 Aug 2023 18:04:05 +0200 Content-Type: text/plain; charset=utf-8 Mime-Version: 1.0 (Mac OS X Mail 16.0 \(3771.100.2\)) Subject: Re: GCC support for extensions from later standards From: Nikolas Klauser In-Reply-To: Date: Tue, 8 Aug 2023 09:03:49 -0700 Cc: Jason Merrill , gcc@gcc.gnu.org, Louis Dionne , Mark de Wever , aaron@aaronballman.com, libstdc++ Content-Transfer-Encoding: quoted-printable Message-Id: <949026CD-7150-4281-9C28-4485C81C62F7@berlin.de> References: <3A4C9996-750B-4E3F-8F30-E3DA4366C7B5@berlin.de> <19c14d57-574b-9b31-de5a-a0590e189ce6@berlin.de> To: Jakub Jelinek X-Mailer: Apple Mail (2.3771.100.2) X-VISP-ShouldScan: 1 X-VISP-Virus-Check: clean X-VISP-Spam-Score: -0.5 (/) X-VISP-Spam-Report: This message has been scanned on "cosmopolitan.snafu.de" to identify if it is considered spam or not. Contact the support hotline for details. Content analysis details: (-0.5 points) pts rule name description ---- ---------------------- -------------------------------------------------- -1.0 ALL_TRUSTED Passed through trusted hosts only via SMTP 0.5 FREEMAIL_FROM Sender email is commonly abused enduser mail provider [nikolasklauser[at]berlin.de] 0.0 KAM_DMARC_STATUS Test Rule for DKIM or SPF Failure with Strict Alignment X-VISP-Spam-Max-Score: +++++ X-SA-Exim-Connect-IP: 73.231.7.242 X-SA-Exim-Mail-From: nikolasklauser@berlin.de X-SA-Exim-Scanned: No (on cosmopolitan.snafu.de); SAEximRunCond expanded to false X-Spam-Status: No, score=-1.2 required=5.0 tests=BAYES_00,FREEMAIL_FROM,KAM_DMARC_STATUS,RCVD_IN_DNSWL_LOW,SPF_HELO_PASS,TXREP,T_SPF_PERMERROR 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: Luckily most of these aren=E2=80=99t problems for libc++. We only = support the latest GCC. We can only use `if constexpr` in C++11, but = that is already a win I think. Nikolas > On Aug 8, 2023, at 12:33=E2=80=AFAM, Jakub Jelinek = wrote: >=20 > On Mon, Aug 07, 2023 at 08:03:05PM -0700, Nikolas Klauser wrote: >> Thanks for the answers! >>=20 >> There are a few really interesting extensions that I would like to = use: >>=20 >> - inline variables >> - variable templates >> - `if constexpr` >> - fold expressions >> - conditional explicit >> - static operator() >=20 > There are multiple problems. >=20 > cat /tmp/test.h > #pragma GCC system_header > inline int a =3D 1; > template int b =3D N; > void foo () { if constexpr (true) {} } > template bool bar (A... a) { return (... + a); } > struct S { template explicit (N =3D=3D 42) S (int (&)[N]) {} = }; > struct T { static constexpr bool operator () (S const &x, S const &y) = { return false; }; }; > void baz () { auto a =3D [](int x, int y) static { return x + y; }; } > cat /tmp/test.C > #include "/tmp/test.h" > g++ -S -std=3Dc++11 -o /tmp/test.{s,C} >=20 > The above with GCC 13 doesn't give any warnings, but does with = -Wsystem-headers: > In file included from /tmp/test.C:1: > /tmp/test.h:2:1: warning: inline variables are only available with = =E2=80=98-std=3Dc++17=E2=80=99 or =E2=80=98-std=3Dgnu++17=E2=80=99 = [-Wc++17-extensions] > 2 | inline int a =3D 1; > | ^~~~~~ > /tmp/test.h:3:22: warning: variable templates only available with = =E2=80=98-std=3Dc++14=E2=80=99 or =E2=80=98-std=3Dgnu++14=E2=80=99 = [-Wc++14-extensions] > 3 | template int b =3D N; > | ^ > /tmp/test.h: In function =E2=80=98void foo()=E2=80=99: > /tmp/test.h:4:18: warning: =E2=80=98if constexpr=E2=80=99 only = available with =E2=80=98-std=3Dc++17=E2=80=99 or =E2=80=98-std=3Dgnu++17=E2= =80=99 [-Wc++17-extensions] > 4 | void foo () { if constexpr (true) {} } > | ^~~~~~~~~ > /tmp/test.h: In function =E2=80=98bool bar(A ...)=E2=80=99: > /tmp/test.h:5:59: warning: fold-expressions only available with = =E2=80=98-std=3Dc++17=E2=80=99 or =E2=80=98-std=3Dgnu++17=E2=80=99 = [-Wc++17-extensions] > 5 | template bool bar (A... a) { return (... + a); } > | ^ > /tmp/test.h: At global scope: > /tmp/test.h:6:29: warning: =E2=80=98explicit(bool)=E2=80=99 only = available with =E2=80=98-std=3Dc++20=E2=80=99 or =E2=80=98-std=3Dgnu++20=E2= =80=99 [-Wc++20-extensions] > 6 | struct S { template explicit (N =3D=3D 42) S (int = (&)[N]) {} }; > | ^~~~~~~~ > /tmp/test.h:7:34: warning: =E2=80=98static constexpr bool = T::operator()(const S&, const S&)=E2=80=99 may be a static member = function only with =E2=80=98-std=3Dc++23=E2=80=99 or =E2=80=98-std=3Dgnu++= 23=E2=80=99 [-Wc++23-extensions] > 7 | struct T { static constexpr bool operator () (S const &x, S = const &y) { return false; }; }; > | ^~~~~~~~ > /tmp/test.h: In function =E2=80=98void baz()=E2=80=99: > /tmp/test.h:8:41: warning: =E2=80=98static=E2=80=99 only valid in = lambda with =E2=80=98-std=3Dc++23=E2=80=99 or =E2=80=98-std=3Dgnu++23=E2=80= =99 [-Wc++23-extensions] > 8 | void baz () { auto a =3D [](int x, int y) static { return x + = y; }; } > | ^~~~~~ > and with -pedantic-errors -Wsystem-headers even errors: > ./xg++ -B ./ -S /tmp/test.C -std=3Dc++11 -pedantic-errors = -Wsystem-headers > In file included from /tmp/test.C:1: > /tmp/test.h:2:1: error: inline variables are only available with = =E2=80=98-std=3Dc++17=E2=80=99 or =E2=80=98-std=3Dgnu++17=E2=80=99 = [-Wc++17-extensions] > 2 | inline int a =3D 1; > | ^~~~~~ > /tmp/test.h:3:22: error: variable templates only available with = =E2=80=98-std=3Dc++14=E2=80=99 or =E2=80=98-std=3Dgnu++14=E2=80=99 = [-Wc++14-extensions] > 3 | template int b =3D N; > | ^ > /tmp/test.h: In function =E2=80=98void foo()=E2=80=99: > /tmp/test.h:4:18: error: =E2=80=98if constexpr=E2=80=99 only available = with =E2=80=98-std=3Dc++17=E2=80=99 or =E2=80=98-std=3Dgnu++17=E2=80=99 = [-Wc++17-extensions] > 4 | void foo () { if constexpr (true) {} } > | ^~~~~~~~~ > /tmp/test.h: In function =E2=80=98bool bar(A ...)=E2=80=99: > /tmp/test.h:5:59: error: fold-expressions only available with = =E2=80=98-std=3Dc++17=E2=80=99 or =E2=80=98-std=3Dgnu++17=E2=80=99 = [-Wc++17-extensions] > 5 | template bool bar (A... a) { return (... + a); } > | ^ > /tmp/test.h: At global scope: > /tmp/test.h:6:29: error: =E2=80=98explicit(bool)=E2=80=99 only = available with =E2=80=98-std=3Dc++20=E2=80=99 or =E2=80=98-std=3Dgnu++20=E2= =80=99 [-Wc++20-extensions] > 6 | struct S { template explicit (N =3D=3D 42) S (int = (&)[N]) {} }; > | ^~~~~~~~ > /tmp/test.h:7:34: error: =E2=80=98static constexpr bool = T::operator()(const S&, const S&)=E2=80=99 may be a static member = function only with =E2=80=98-std=3Dc++23=E2=80=99 or =E2=80=98-std=3Dgnu++= 23=E2=80=99 [-Wc++23-extensions] > 7 | struct T { static constexpr bool operator () (S const &x, S = const &y) { return false; }; }; > | ^~~~~~~~ > /tmp/test.h: In function =E2=80=98void baz()=E2=80=99: > /tmp/test.h:8:41: error: =E2=80=98static=E2=80=99 only valid in lambda = with =E2=80=98-std=3Dc++23=E2=80=99 or =E2=80=98-std=3Dgnu++23=E2=80=99 = [-Wc++23-extensions] > 8 | void baz () { auto a =3D [](int x, int y) static { return x + = y; }; } > | ^~~~~~ > (so one would need to figure out if __extension__ somewhere around = would be > able to quite that up or not, or > #pragma GCC diagnostic ignored "-Wc++14-extensions" (and 17, 20 and = 23). >=20 > Also, static operator () is only in GCC 13 and later, earlier versions = will > error on that. The -Wc++*-extensions separate warnings are only in = GCC 12 > and later, before that it will be harder to quiet the warnings = selectively. > Similarly, conditional explicit is only GCC 9 and later, if constexpr = and > inline vars GCC 7 and later, fold expressions GCC 6 and later, and = variable > templates GCC 5 and later. And in C++98 some of these don't work at = all, > if constexpr and static lambdas (because constexpr isn't a keyword > and lambdas aren't supported altogether). >=20 > Jakub >=20