From 761df90687c2cda775d86491b54d549bf57e9bc1 Mon Sep 17 00:00:00 2001 From: Jakub Jelinek Date: Fri, 22 Nov 2019 20:55:38 +0100 Subject: [PATCH] Implement P1902R1, Missing feature-test macros 2017-2019. * c-cppbuiltin.c (c_cpp_builtins): Bump __cpp_init_captures and __cpp_generic_lambdas for -std=c++2a. Define __cpp_designated_initializers, __cpp_constexpr_in_decltype and __cpp_consteval for -std=c++2a. Remove a FIXME comment about __cpp_concepts for -std=c++2a. * g++.dg/cpp1z/feat-cxx1z.C: Only compile with -std=c++17. * g++.dg/cpp2a/feat-cxx2a.C: Adjust for P1902R1 changes. * g++.dg/cpp2a/desig15.C: New test. * g++.dg/cpp2a/lambda-pack-init3.C: New test. * g++.dg/cpp2a/lambda-generic6.C: New test. * g++.dg/cpp2a/consteval15.C: New test. From-SVN: r278628 --- gcc/c-family/ChangeLog | 9 ++++++ gcc/c-family/c-cppbuiltin.c | 13 ++++++-- gcc/testsuite/ChangeLog | 8 +++++ gcc/testsuite/g++.dg/cpp1z/feat-cxx1z.C | 4 +-- gcc/testsuite/g++.dg/cpp2a/consteval15.C | 14 ++++++++ gcc/testsuite/g++.dg/cpp2a/desig15.C | 27 ++++++++++++++++ gcc/testsuite/g++.dg/cpp2a/feat-cxx2a.C | 32 ++++++++++++++++--- gcc/testsuite/g++.dg/cpp2a/lambda-generic6.C | 11 +++++++ .../g++.dg/cpp2a/lambda-pack-init3.C | 19 +++++++++++ 9 files changed, 128 insertions(+), 9 deletions(-) create mode 100644 gcc/testsuite/g++.dg/cpp2a/consteval15.C create mode 100644 gcc/testsuite/g++.dg/cpp2a/desig15.C create mode 100644 gcc/testsuite/g++.dg/cpp2a/lambda-generic6.C create mode 100644 gcc/testsuite/g++.dg/cpp2a/lambda-pack-init3.C diff --git a/gcc/c-family/ChangeLog b/gcc/c-family/ChangeLog index 9c93f7f777a..d0b2ba23e6f 100644 --- a/gcc/c-family/ChangeLog +++ b/gcc/c-family/ChangeLog @@ -1,3 +1,12 @@ +2019-11-22 Jakub Jelinek + + Implement P1920R1, Missing feature-test macros 2017-2019. + * c-cppbuiltin.c (c_cpp_builtins): Bump __cpp_init_captures + and __cpp_generic_lambdas for -std=c++2a. Define + __cpp_designated_initializers, __cpp_constexpr_in_decltype and + __cpp_consteval for -std=c++2a. Remove a FIXME comment about + __cpp_concepts for -std=c++2a. + 2019-11-22 Martin Sebor PR middle-end/83859 diff --git a/gcc/c-family/c-cppbuiltin.c b/gcc/c-family/c-cppbuiltin.c index 76d1e4a380e..50066e4dd8b 100644 --- a/gcc/c-family/c-cppbuiltin.c +++ b/gcc/c-family/c-cppbuiltin.c @@ -952,8 +952,11 @@ c_cpp_builtins (cpp_reader *pfile) { /* Set feature test macros for C++14. */ cpp_define (pfile, "__cpp_return_type_deduction=201304L"); - cpp_define (pfile, "__cpp_init_captures=201304L"); - cpp_define (pfile, "__cpp_generic_lambdas=201304L"); + if (cxx_dialect <= cxx17) + { + cpp_define (pfile, "__cpp_init_captures=201304L"); + cpp_define (pfile, "__cpp_generic_lambdas=201304L"); + } if (cxx_dialect <= cxx14) cpp_define (pfile, "__cpp_constexpr=201304L"); cpp_define (pfile, "__cpp_decltype_auto=201304L"); @@ -990,7 +993,12 @@ c_cpp_builtins (cpp_reader *pfile) if (cxx_dialect > cxx17) { /* Set feature test macros for C++2a. */ + cpp_define (pfile, "__cpp_init_captures=201803L"); + cpp_define (pfile, "__cpp_generic_lambdas=201707L"); + cpp_define (pfile, "__cpp_designated_initializers=201707L"); + cpp_define (pfile, "__cpp_constexpr_in_decltype=201711L"); cpp_define (pfile, "__cpp_conditional_explicit=201806L"); + cpp_define (pfile, "__cpp_consteval=201811L"); cpp_define (pfile, "__cpp_constinit=201907L"); cpp_define (pfile, "__cpp_nontype_template_parameter_class=201806L"); cpp_define (pfile, "__cpp_impl_destroying_delete=201806L"); @@ -1000,7 +1008,6 @@ c_cpp_builtins (cpp_reader *pfile) if (flag_concepts) { if (cxx_dialect >= cxx2a) - /* FIXME: Update this to the value required by the IS. */ cpp_define (pfile, "__cpp_concepts=201907L"); else cpp_define (pfile, "__cpp_concepts=201507L"); diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index b3ff86843ee..817fab4b028 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,5 +1,13 @@ 2019-11-22 Jakub Jelinek + Implement P1920R1, Missing feature-test macros 2017-2019. + * g++.dg/cpp1z/feat-cxx1z.C: Only compile with -std=c++17. + * g++.dg/cpp2a/feat-cxx2a.C: Adjust for P1920R1 changes. + * g++.dg/cpp2a/desig15.C: New test. + * g++.dg/cpp2a/lambda-pack-init3.C: New test. + * g++.dg/cpp2a/lambda-generic6.C: New test. + * g++.dg/cpp2a/consteval15.C: New test. + PR tree-optimization/92618 * gcc.c-torture/compile/pr92618.c: New test. * gcc.c-torture/execute/pr92618.c: New test. diff --git a/gcc/testsuite/g++.dg/cpp1z/feat-cxx1z.C b/gcc/testsuite/g++.dg/cpp1z/feat-cxx1z.C index a18d6aea985..55e56a06fe8 100644 --- a/gcc/testsuite/g++.dg/cpp1z/feat-cxx1z.C +++ b/gcc/testsuite/g++.dg/cpp1z/feat-cxx1z.C @@ -1,5 +1,5 @@ -// { dg-do compile { target c++17 } } -// { dg-options "-I${srcdir}/g++.dg/cpp1y -I${srcdir}/g++.dg/cpp1y/testinc" } +// { dg-do compile } +// { dg-options "-std=c++17 -I${srcdir}/g++.dg/cpp1y -I${srcdir}/g++.dg/cpp1y/testinc" } // C++98 features: diff --git a/gcc/testsuite/g++.dg/cpp2a/consteval15.C b/gcc/testsuite/g++.dg/cpp2a/consteval15.C new file mode 100644 index 00000000000..feb77afba01 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp2a/consteval15.C @@ -0,0 +1,14 @@ +// { dg-do compile { target c++11 } } + +#if __cpp_consteval >= 201811L +consteval +#else +constexpr +#endif +int +foo (int x) +{ + return x * x * x * x; +} + +auto a = foo (2); diff --git a/gcc/testsuite/g++.dg/cpp2a/desig15.C b/gcc/testsuite/g++.dg/cpp2a/desig15.C new file mode 100644 index 00000000000..88e9c7284a4 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp2a/desig15.C @@ -0,0 +1,27 @@ +// { dg-do run } +// { dg-options "-pedantic" } + +struct A { int a; }; +struct B { int b; A c; int d; }; +A a = { 1 }; +B c = { 3, { 4 }, 5 }; +#if __cpp_designated_initializers >= 201707L +A b = { .a = 2 }; +B d = { .b = 6, .c { 7 }, .d = 8 }; +B e = { .c = { .a = 9 } }; +#else +A b = { 2 }; +B d = { 6, { 7 }, 8 }; +B e = { 0, { 9 } }; +#endif + +int +main () +{ + if (a.a != 1 || b.a != 2 + || c.b != 3 || c.c.a != 4 || c.d != 5 + || d.b != 6 || d.c.a != 7 || d.d != 8 + || e.b != 0 || e.c.a != 9 || e.d != 0) + __builtin_abort (); + return 0; +} diff --git a/gcc/testsuite/g++.dg/cpp2a/feat-cxx2a.C b/gcc/testsuite/g++.dg/cpp2a/feat-cxx2a.C index 95251c2f5c6..753a6ecd0a8 100644 --- a/gcc/testsuite/g++.dg/cpp2a/feat-cxx2a.C +++ b/gcc/testsuite/g++.dg/cpp2a/feat-cxx2a.C @@ -122,14 +122,14 @@ #ifndef __cpp_init_captures # error "__cpp_init_captures" -#elif __cpp_init_captures != 201304 -# error "__cpp_init_captures != 201304" +#elif __cpp_init_captures != 201803 +# error "__cpp_init_captures != 201803" #endif #ifndef __cpp_generic_lambdas # error "__cpp_generic_lambdas" -#elif __cpp_generic_lambdas != 201304 -# error "__cpp_generic_lambdas != 201304" +#elif __cpp_generic_lambdas != 201707 +# error "__cpp_generic_lambdas != 201707" #endif #ifndef __cpp_constexpr @@ -507,3 +507,27 @@ #elif __cpp_char8_t != 201811 # error "__cpp_char8_t != 201811" #endif + +#ifndef __cpp_designated_initializers +# error "__cpp_designated_initializers" +#elif __cpp_designated_initializers != 201707 +# error "__cpp_designated_initializers != 201707" +#endif + +#ifndef __cpp_constexpr_in_decltype +# error "__cpp_constexpr_in_decltype" +#elif __cpp_constexpr_in_decltype != 201711 +# error "__cpp_constexpr_in_decltype != 201711" +#endif + +#ifndef __cpp_consteval +# error "__cpp_consteval" +#elif __cpp_consteval != 201811 +# error "__cpp_consteval != 201811" +#endif + +#ifndef __cpp_concepts +# error "__cpp_concepts" +#elif __cpp_concepts != 201907 +# error "__cpp_concepts != 201907" +#endif diff --git a/gcc/testsuite/g++.dg/cpp2a/lambda-generic6.C b/gcc/testsuite/g++.dg/cpp2a/lambda-generic6.C new file mode 100644 index 00000000000..7ab12d16e47 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp2a/lambda-generic6.C @@ -0,0 +1,11 @@ +// P0428R2 +// { dg-do compile { target c++14 } } + +struct S { int s; }; + +auto x = +#if __cpp_generic_lambdas >= 201707 + [](T &&t) { return t.s; } ({ 2 }); +#else + [](auto &&t) { return t.s; } (S { 2 }); +#endif diff --git a/gcc/testsuite/g++.dg/cpp2a/lambda-pack-init3.C b/gcc/testsuite/g++.dg/cpp2a/lambda-pack-init3.C new file mode 100644 index 00000000000..0ed5ddf2084 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp2a/lambda-pack-init3.C @@ -0,0 +1,19 @@ +// { dg-do compile { target c++11 } } + +void bar(); +void bar(int); + +template +void foo(Args... args) { +#if __cpp_init_captures >= 201803 + auto f = [...xs=args]{ + bar(xs...); + }; +#endif +} + +int main() +{ + foo(); + foo(1); +} -- 2.30.2