PR c++/88538 - braced-init-list in template-argument-list.
authorMarek Polacek <polacek@redhat.com>
Tue, 8 Jan 2019 22:33:04 +0000 (22:33 +0000)
committerMarek Polacek <mpolacek@gcc.gnu.org>
Tue, 8 Jan 2019 22:33:04 +0000 (22:33 +0000)
* parser.c (cp_parser_template_argument): Handle braced-init-list when
in C++20.

* g++.dg/cpp2a/nontype-class11.C: New test.

From-SVN: r267741

gcc/cp/ChangeLog
gcc/cp/parser.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/cpp2a/nontype-class11.C [new file with mode: 0644]

index f3b5dbe68bc31ff401b005aa063fceca3526b612..91465daea613b7d7de17f2466af83ae35afbd2f2 100644 (file)
@@ -1,5 +1,9 @@
 2019-01-08  Marek Polacek  <polacek@redhat.com>
 
+       PR c++/88538 - braced-init-list in template-argument-list.
+       * parser.c (cp_parser_template_argument): Handle braced-init-list when
+       in C++20.
+
        PR c++/88548 - this accepted in static member functions.
        * parser.c (cp_debug_parser): Adjust printing of
        local_variables_forbidden_p.
index ca75c010e22e32fe25ad777a3d50596d5b3bf08a..f441943dc8e69ba8c3e82658711986eec762c5af 100644 (file)
@@ -17026,6 +17026,14 @@ cp_parser_template_argument (cp_parser* parser)
     argument = cp_parser_constant_expression (parser);
   else
     {
+      /* In C++20, we can encounter a braced-init-list.  */
+      if (cxx_dialect >= cxx2a
+         && cp_lexer_next_token_is (parser->lexer, CPP_OPEN_BRACE))
+       {
+         bool expr_non_constant_p;
+         return cp_parser_braced_list (parser, &expr_non_constant_p);
+       }
+
       /* With C++17 generalized non-type template arguments we need to handle
         lvalue constant expressions, too.  */
       argument = cp_parser_assignment_expression (parser);
index 634111bfc14dd4835a745b1781b760c9b1643430..f7b37d96ed9bcbb0f60de35fb677e71393726800 100644 (file)
@@ -1,3 +1,8 @@
+2019-01-08  Marek Polacek  <polacek@redhat.com>
+
+       PR c++/88538 - braced-init-list in template-argument-list.
+       * g++.dg/cpp2a/nontype-class11.C: New test.
+
 2019-01-08  Jakub Jelinek  <jakub@redhat.com>
 
        PR target/88457
diff --git a/gcc/testsuite/g++.dg/cpp2a/nontype-class11.C b/gcc/testsuite/g++.dg/cpp2a/nontype-class11.C
new file mode 100644 (file)
index 0000000..8a06d23
--- /dev/null
@@ -0,0 +1,21 @@
+// PR c++/88538
+// { dg-do compile { target c++2a } }
+
+struct S {
+  unsigned a;
+  unsigned b;
+  constexpr S(unsigned _a, unsigned _b) noexcept: a{_a}, b{_b} { }
+};
+
+template <S p>
+void fnc()
+{
+}
+
+template<S s> struct X { };
+
+void f()
+{
+  fnc<{10,20}>();
+  X<{1, 2}> x;
+}