From 96e768c3fecf0f65af3f289293145d5740971e2a Mon Sep 17 00:00:00 2001 From: Marek Polacek Date: Tue, 8 Jan 2019 22:33:04 +0000 Subject: [PATCH] PR c++/88538 - braced-init-list in template-argument-list. * 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 | 4 ++++ gcc/cp/parser.c | 8 ++++++++ gcc/testsuite/ChangeLog | 5 +++++ gcc/testsuite/g++.dg/cpp2a/nontype-class11.C | 21 ++++++++++++++++++++ 4 files changed, 38 insertions(+) create mode 100644 gcc/testsuite/g++.dg/cpp2a/nontype-class11.C diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index f3b5dbe68bc..91465daea61 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,5 +1,9 @@ 2019-01-08 Marek Polacek + 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. diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c index ca75c010e22..f441943dc8e 100644 --- a/gcc/cp/parser.c +++ b/gcc/cp/parser.c @@ -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); diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 634111bfc14..f7b37d96ed9 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2019-01-08 Marek Polacek + + PR c++/88538 - braced-init-list in template-argument-list. + * g++.dg/cpp2a/nontype-class11.C: New test. + 2019-01-08 Jakub Jelinek 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 index 00000000000..8a06d23904b --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp2a/nontype-class11.C @@ -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 +void fnc() +{ +} + +template struct X { }; + +void f() +{ + fnc<{10,20}>(); + X<{1, 2}> x; +} -- 2.30.2