From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from longisland.snafu.de (longisland.snafu.de [IPv6:2001:1560:3:255::153]) by sourceware.org (Postfix) with ESMTPS id D91583858D20; Tue, 8 Aug 2023 16:34:13 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org D91583858D20 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 2e372e3234327c3171545065732d3030305041352d44657c313639313531323435 30 Received: from longisland.snafu.de ([10.153.10.49] helo=localhost) by longisland.snafu.de with esmtpsa (Exim 4.94.2) id 1qTPes-000PA5-De; Tue, 08 Aug 2023 18:34:11 +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:33:56 -0700 Cc: Jakub Jelinek , Jason Merrill , gcc@gcc.gnu.org, Louis Dionne , Mark de Wever , aaron@aaronballman.com, libstdc++ Content-Transfer-Encoding: quoted-printable Message-Id: <675C38C8-3AA7-4974-BBB1-88ED8BBEB794@berlin.de> References: <3A4C9996-750B-4E3F-8F30-E3DA4366C7B5@berlin.de> <19c14d57-574b-9b31-de5a-a0590e189ce6@berlin.de> <949026CD-7150-4281-9C28-4485C81C62F7@berlin.de> To: Jonathan Wakely 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 "longisland.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 longisland.snafu.de); SAEximRunCond expanded to false X-Spam-Status: No, score=-2.1 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: Yes, Clang allows it. Most importantly though: you don=E2=80=99t have to = be in a constexpr function for `if constexpr` to be useful. e.g. the = Algorithms aren=E2=80=99t constexpr until C++20, but a lot of them have = overloads for improving the algorithm based on the iterator category. = Having `if constexpr` there instead of enable_ifs seems like quite a = nice improvement to me. The main problem is probably that libc++ = back-ports a lot of the C++11 stuff to C++03, so in these cases `if = constexpr` won=E2=80=99t help. > On Aug 8, 2023, at 9:10=E2=80=AFAM, Jonathan Wakely = wrote: >=20 > On Tue, 8 Aug 2023 at 17:07, Jonathan Wakely wrote: >>=20 >> On Tue, 8 Aug 2023 at 17:04, Nikolas Klauser wrote: >>>=20 >>> 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. >>=20 >> Can you use it in C++11 though? The body of a constexpr function must >> be a single return statement, so if-constexpr isn't allowed. >=20 > Clang allows it with multiple warnings: >=20 > ifc.cc:3:6: warning: constexpr if is a C++17 extension = [-Wc++17-extensions] > if constexpr (sizeof(i) >=3D 4) > ^ > ifc.cc:3:3: warning: use of this statement in a constexpr function is > a C++14 extension [-Wc++14-extensions] > if constexpr (sizeof(i) >=3D 4) > ^ > ifc.cc:8:5: warning: multiple return statements in constexpr function > is a C++14 extension [-Wc++14-extensions] > return 0; > ^ > ifc.cc:5:5: note: previous return statement is here > return i << 3; > ^ >=20 > But GCC gives a warning for if-constexpr and then an error for the > invalid function body: >=20 > ifc.cc: In function 'constexpr int f(int)': > ifc.cc:3:6: warning: 'if constexpr' only available with '-std=3Dc++17' > or '-std=3Dgnu++17' [-Wc++17-extensions] > 3 | if constexpr (sizeof(i) >=3D 4) > | ^~~~~~~~~ > ifc.cc:9:1: error: body of 'constexpr' function 'constexpr int f(int)' > not a return-statement > 9 | } > | ^