Implement P1902R1, Missing feature-test macros 2017-2019.
authorJakub Jelinek <jakub@redhat.com>
Fri, 22 Nov 2019 19:55:38 +0000 (20:55 +0100)
committerJakub Jelinek <jakub@gcc.gnu.org>
Fri, 22 Nov 2019 19:55:38 +0000 (20:55 +0100)
* 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
gcc/c-family/c-cppbuiltin.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/cpp1z/feat-cxx1z.C
gcc/testsuite/g++.dg/cpp2a/consteval15.C [new file with mode: 0644]
gcc/testsuite/g++.dg/cpp2a/desig15.C [new file with mode: 0644]
gcc/testsuite/g++.dg/cpp2a/feat-cxx2a.C
gcc/testsuite/g++.dg/cpp2a/lambda-generic6.C [new file with mode: 0644]
gcc/testsuite/g++.dg/cpp2a/lambda-pack-init3.C [new file with mode: 0644]

index 9c93f7f777aafa48c2cc505dd47a07239b4a68b4..d0b2ba23e6f74b440b47003f0632290b4f791ad9 100644 (file)
@@ -1,3 +1,12 @@
+2019-11-22  Jakub Jelinek  <jakub@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.
+
 2019-11-22  Martin Sebor  <msebor@redhat.com>
 
        PR middle-end/83859
index 76d1e4a380e03495d2036bcead9e13e117c40c04..50066e4dd8ba8013f3101307b16a0cb4245d073d 100644 (file)
@@ -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");
index b3ff86843ee6e1f7cd9a82f18959654a78da1dad..817fab4b02855402326cf03db30d15911aa063c9 100644 (file)
@@ -1,5 +1,13 @@
 2019-11-22  Jakub Jelinek  <jakub@redhat.com>
 
+       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.
index a18d6aea985159ad8c5f55e2096a8c462abb8594..55e56a06fe8f394e16bcb6a320fb24343c496fdd 100644 (file)
@@ -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 (file)
index 0000000..feb77af
--- /dev/null
@@ -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 (file)
index 0000000..88e9c72
--- /dev/null
@@ -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;
+}
index 95251c2f5c692b0df8d40fca4e2b6ffadd772273..753a6ecd0a85e82bb75d4e709484fa2b800043a7 100644 (file)
 
 #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
 #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 (file)
index 0000000..7ab12d1
--- /dev/null
@@ -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
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 (file)
index 0000000..0ed5ddf
--- /dev/null
@@ -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);
+}