On 11/16/19 7:38 PM, Jakub Jelinek wrote:
Hi!
This implements the core part of P1920R1, tested on x86_64-linux,
ok for trunk if it passes full bootstrap/regtest?
Jon, are you going to handle the libstdc++ side of this, assuming
there is something still not done where we have the corresponding
features implemented already?
OK.
2019-11-16 Jakub Jelinek <ja...@redhat.com>
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.
* 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.
--- gcc/c-family/c-cppbuiltin.c.jj 2019-11-13 19:13:15.490048963 +0100
+++ gcc/c-family/c-cppbuiltin.c 2019-11-16 18:30:02.338883062 +0100
@@ -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");
--- gcc/testsuite/g++.dg/cpp1z/feat-cxx1z.C.jj 2019-10-19 09:22:15.756879262
+0200
+++ gcc/testsuite/g++.dg/cpp1z/feat-cxx1z.C 2019-11-16 18:34:08.045190225
+0100
@@ -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:
--- gcc/testsuite/g++.dg/cpp2a/feat-cxx2a.C.jj 2019-10-19 09:22:16.168872968 +0200
+++ gcc/testsuite/g++.dg/cpp2a/feat-cxx2a.C 2019-11-16 18:42:37.817528261
+0100
@@ -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
--- gcc/testsuite/g++.dg/cpp2a/desig15.C.jj 2019-11-16 19:07:37.527982693
+0100
+++ gcc/testsuite/g++.dg/cpp2a/desig15.C 2019-11-16 19:09:25.630357282
+0100
@@ -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;
+}
--- gcc/testsuite/g++.dg/cpp2a/lambda-pack-init3.C.jj 2019-11-16
19:05:00.170348712 +0100
+++ gcc/testsuite/g++.dg/cpp2a/lambda-pack-init3.C 2019-11-16
19:06:34.101936361 +0100
@@ -0,0 +1,19 @@
+// { dg-do compile { target c++11 } }
+
+void bar();
+void bar(int);
+
+template <typename... Args>
+void foo(Args... args) {
+#if __cpp_init_captures >= 201803
+ auto f = [...xs=args]{
+ bar(xs...);
+ };
+#endif
+}
+
+int main()
+{
+ foo();
+ foo(1);
+}
--- gcc/testsuite/g++.dg/cpp2a/lambda-generic6.C.jj 2019-11-16
19:01:25.504576417 +0100
+++ gcc/testsuite/g++.dg/cpp2a/lambda-generic6.C 2019-11-16
19:02:58.616176396 +0100
@@ -0,0 +1,11 @@
+// P0428R2
+// { dg-do compile { target c++14 } }
+
+struct S { int s; };
+
+auto x =
+#if __cpp_generic_lambdas >= 201707
+ []<class T = S>(T &&t) { return t.s; } ({ 2 });
+#else
+ [](auto &&t) { return t.s; } (S { 2 });
+#endif
--- gcc/testsuite/g++.dg/cpp2a/consteval15.C.jj 2019-11-16 19:12:50.352279212
+0100
+++ gcc/testsuite/g++.dg/cpp2a/consteval15.C 2019-11-16 19:12:44.631365186
+0100
@@ -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);
Jakub