From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by sourceware.org (Postfix) with ESMTPS id AF92A3858D33 for ; Tue, 8 Aug 2023 07:33:20 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org AF92A3858D33 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1691480000; h=from:from:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=LHQmUI/CZNWq6KQ2+TqeQ/Yt5deEZ17AUqTEPv9BF24=; b=bh34D82uJVOunxvW5gaSIWu2IbwztVd87A9MUKmineNUoyuKbJFqlyE9UB7j/yE8e1DM5j pWnh5gZMG3T+f1bGRw/FaytxPamIqElHyQBjD4sB8YEXT5NvtDQ4aszBkvUGacaFqfQTXD aZYnmpf7RZkj/mB9yrkScCPST+H52cQ= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-597-ENZ40UDbNv2maVBpYp4q5A-1; Tue, 08 Aug 2023 03:33:18 -0400 X-MC-Unique: ENZ40UDbNv2maVBpYp4q5A-1 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.rdu2.redhat.com [10.11.54.8]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id AEEFA8007CE; Tue, 8 Aug 2023 07:33:17 +0000 (UTC) Received: from tucnak.zalov.cz (unknown [10.45.224.18]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 52F2DC15BAD; Tue, 8 Aug 2023 07:33:17 +0000 (UTC) Received: from tucnak.zalov.cz (localhost [127.0.0.1]) by tucnak.zalov.cz (8.17.1/8.17.1) with ESMTPS id 3787XEdw3691054 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Tue, 8 Aug 2023 09:33:14 +0200 Received: (from jakub@localhost) by tucnak.zalov.cz (8.17.1/8.17.1/Submit) id 3787XCuQ3691051; Tue, 8 Aug 2023 09:33:12 +0200 Date: Tue, 8 Aug 2023 09:33:12 +0200 From: Jakub Jelinek To: Nikolas Klauser Cc: Jason Merrill , gcc@gcc.gnu.org, Louis Dionne , Mark de Wever , aaron@aaronballman.com, libstdc++ Subject: Re: GCC support for extensions from later standards Message-ID: Reply-To: Jakub Jelinek References: <3A4C9996-750B-4E3F-8F30-E3DA4366C7B5@berlin.de> <19c14d57-574b-9b31-de5a-a0590e189ce6@berlin.de> MIME-Version: 1.0 In-Reply-To: <19c14d57-574b-9b31-de5a-a0590e189ce6@berlin.de> X-Scanned-By: MIMEDefang 3.1 on 10.11.54.8 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-3.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H4,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_NONE,TXREP 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: On Mon, Aug 07, 2023 at 08:03:05PM -0700, Nikolas Klauser wrote: > Thanks for the answers! > > There are a few really interesting extensions that I would like to use: > > - inline variables > - variable templates > - `if constexpr` > - fold expressions > - conditional explicit > - static operator() There are multiple problems. cat /tmp/test.h #pragma GCC system_header inline int a = 1; template int b = N; void foo () { if constexpr (true) {} } template bool bar (A... a) { return (... + a); } struct S { template explicit (N == 42) S (int (&)[N]) {} }; struct T { static constexpr bool operator () (S const &x, S const &y) { return false; }; }; void baz () { auto a = [](int x, int y) static { return x + y; }; } cat /tmp/test.C #include "/tmp/test.h" g++ -S -std=c++11 -o /tmp/test.{s,C} 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 ‘-std=c++17’ or ‘-std=gnu++17’ [-Wc++17-extensions] 2 | inline int a = 1; | ^~~~~~ /tmp/test.h:3:22: warning: variable templates only available with ‘-std=c++14’ or ‘-std=gnu++14’ [-Wc++14-extensions] 3 | template int b = N; | ^ /tmp/test.h: In function ‘void foo()’: /tmp/test.h:4:18: warning: ‘if constexpr’ only available with ‘-std=c++17’ or ‘-std=gnu++17’ [-Wc++17-extensions] 4 | void foo () { if constexpr (true) {} } | ^~~~~~~~~ /tmp/test.h: In function ‘bool bar(A ...)’: /tmp/test.h:5:59: warning: fold-expressions only available with ‘-std=c++17’ or ‘-std=gnu++17’ [-Wc++17-extensions] 5 | template bool bar (A... a) { return (... + a); } | ^ /tmp/test.h: At global scope: /tmp/test.h:6:29: warning: ‘explicit(bool)’ only available with ‘-std=c++20’ or ‘-std=gnu++20’ [-Wc++20-extensions] 6 | struct S { template explicit (N == 42) S (int (&)[N]) {} }; | ^~~~~~~~ /tmp/test.h:7:34: warning: ‘static constexpr bool T::operator()(const S&, const S&)’ may be a static member function only with ‘-std=c++23’ or ‘-std=gnu++23’ [-Wc++23-extensions] 7 | struct T { static constexpr bool operator () (S const &x, S const &y) { return false; }; }; | ^~~~~~~~ /tmp/test.h: In function ‘void baz()’: /tmp/test.h:8:41: warning: ‘static’ only valid in lambda with ‘-std=c++23’ or ‘-std=gnu++23’ [-Wc++23-extensions] 8 | void baz () { auto a = [](int x, int y) static { return x + y; }; } | ^~~~~~ and with -pedantic-errors -Wsystem-headers even errors: ./xg++ -B ./ -S /tmp/test.C -std=c++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 ‘-std=c++17’ or ‘-std=gnu++17’ [-Wc++17-extensions] 2 | inline int a = 1; | ^~~~~~ /tmp/test.h:3:22: error: variable templates only available with ‘-std=c++14’ or ‘-std=gnu++14’ [-Wc++14-extensions] 3 | template int b = N; | ^ /tmp/test.h: In function ‘void foo()’: /tmp/test.h:4:18: error: ‘if constexpr’ only available with ‘-std=c++17’ or ‘-std=gnu++17’ [-Wc++17-extensions] 4 | void foo () { if constexpr (true) {} } | ^~~~~~~~~ /tmp/test.h: In function ‘bool bar(A ...)’: /tmp/test.h:5:59: error: fold-expressions only available with ‘-std=c++17’ or ‘-std=gnu++17’ [-Wc++17-extensions] 5 | template bool bar (A... a) { return (... + a); } | ^ /tmp/test.h: At global scope: /tmp/test.h:6:29: error: ‘explicit(bool)’ only available with ‘-std=c++20’ or ‘-std=gnu++20’ [-Wc++20-extensions] 6 | struct S { template explicit (N == 42) S (int (&)[N]) {} }; | ^~~~~~~~ /tmp/test.h:7:34: error: ‘static constexpr bool T::operator()(const S&, const S&)’ may be a static member function only with ‘-std=c++23’ or ‘-std=gnu++23’ [-Wc++23-extensions] 7 | struct T { static constexpr bool operator () (S const &x, S const &y) { return false; }; }; | ^~~~~~~~ /tmp/test.h: In function ‘void baz()’: /tmp/test.h:8:41: error: ‘static’ only valid in lambda with ‘-std=c++23’ or ‘-std=gnu++23’ [-Wc++23-extensions] 8 | void baz () { auto a = [](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). 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). Jakub