]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
c++: Fix up __has_extension (cxx_init_captures)
authorJakub Jelinek <jakub@redhat.com>
Tue, 28 Nov 2023 17:25:14 +0000 (18:25 +0100)
committerJakub Jelinek <jakub@redhat.com>
Tue, 28 Nov 2023 17:25:14 +0000 (18:25 +0100)
On Mon, Nov 27, 2023 at 10:58:04AM +0000, Alex Coplan wrote:
> Many thanks both for the reviews, this is now pushed (with Jason's
> above changes implemented) as g:06280a906cb3dc80cf5e07cf3335b758848d488d.

The new test FAILs everywhere with GXX_TESTSUITE_STDS=98,11,14,17,20,2b
I'm normally using for testing.
FAIL: g++.dg/ext/has-feature.C  -std=gnu++11 (test for excess errors)
Excess errors:
/home/jakub/src/gcc/gcc/testsuite/g++.dg/ext/has-feature.C:185:2: error: #error

This is on
 #if __has_extension (cxx_init_captures) != CXX11
 #error
 #endif
Comparing the values with clang++ on godbolt and with what is actually
implemented:
void foo () { auto a = [b = 3]() { return b; }; }
both clang++ and GCC implement init captures as extension already in C++11
(and obviously not in C++98 because lambdas aren't implemented there),
unless -pedantic-errors/-Werror=pedantic, so I think we should change
the FE to match the test rather than the other way around.

Making __has_extension return __has_feature for -pedantic-errors and not
for -Werror=pedantic is just weird, but as that is what clang++ implements
and this is for compatibility with it, I can live with it (but perhaps
we should mention it in the documentation).  Note, the warnings/errors
can be changed using pragmas inside of the source, so whether one can
use an extension or not depends on where in the code it is (__extension__
to the rescue if it can be specified around it).
I wonder if the has-feature.C test shouldn't be #included in other 2 tests,
one where -pedantic-errors would be in dg-options and through some macro
tell the file that __has_extension will behave like __has_feature, and
another with -Werror=pedantic to document that the option doesn't change
it.

2023-11-28  Jakub Jelinek  <jakub@redhat.com>

* cp-objcp-common.cc (cp_feature_table): Evaluate
__has_extension (cxx_init_captures) to 1 even for -std=c++11.

gcc/cp/cp-objcp-common.cc

index 70f9e4ab9e4ac0b2be36ba0dea0adbfa8c0b1fb0..9439c4dc74440ac1592aa5c2b28be7c92a4532c3 100644 (file)
@@ -145,7 +145,7 @@ static constexpr cp_feature_info cp_feature_table[] =
   { "cxx_contextual_conversions", { cxx14, cxx98 } },
   { "cxx_decltype_auto", cxx14 },
   { "cxx_aggregate_nsdmi", cxx14 },
-  { "cxx_init_captures", cxx14 },
+  { "cxx_init_captures", { cxx14, cxx11 } },
   { "cxx_generic_lambdas", cxx14 },
   { "cxx_relaxed_constexpr", cxx14 },
   { "cxx_return_type_deduction", cxx14 },