From eedaaaf7d7892011245b1e2054ca917c6d81c213 Mon Sep 17 00:00:00 2001 From: Jason Merrill Date: Thu, 1 Mar 2018 14:40:36 -0500 Subject: [PATCH] PR c++/71569 - decltype of template. * parser.c (cp_parser_decltype_expr): Handle missing template args. From-SVN: r258110 --- gcc/cp/ChangeLog | 5 +++++ gcc/cp/parser.c | 7 +++++++ gcc/testsuite/g++.dg/cpp0x/decltype-33837.C | 4 ++-- gcc/testsuite/g++.dg/cpp0x/decltype43.C | 2 +- gcc/testsuite/g++.dg/cpp1y/var-templ59.C | 14 ++++++++++++++ 5 files changed, 29 insertions(+), 3 deletions(-) create mode 100644 gcc/testsuite/g++.dg/cpp1y/var-templ59.C diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index acaabd0e197..df5f48c845b 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,8 @@ +2018-03-01 Jason Merrill + + PR c++/71569 - decltype of template. + * parser.c (cp_parser_decltype_expr): Handle missing template args. + 2018-03-01 Marek Polacek PR c++/84596 diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c index 359460cd4d8..e1acb07d29e 100644 --- a/gcc/cp/parser.c +++ b/gcc/cp/parser.c @@ -13983,6 +13983,10 @@ cp_parser_decltype_expr (cp_parser *parser, expr = cp_parser_lookup_name_simple (parser, expr, id_expr_start_token->location); + if (expr && TREE_CODE (expr) == TEMPLATE_DECL) + /* A template without args is not a complete id-expression. */ + expr = error_mark_node; + if (expr && expr != error_mark_node && TREE_CODE (expr) != TYPE_DECL @@ -14048,6 +14052,9 @@ cp_parser_decltype_expr (cp_parser *parser, expression. */ cp_parser_abort_tentative_parse (parser); + /* Commit to the tentative_firewall so we get syntax errors. */ + cp_parser_commit_to_tentative_parse (parser); + /* Parse a full expression. */ expr = cp_parser_expression (parser, /*pidk=*/NULL, /*cast_p=*/false, /*decltype_p=*/true); diff --git a/gcc/testsuite/g++.dg/cpp0x/decltype-33837.C b/gcc/testsuite/g++.dg/cpp0x/decltype-33837.C index fbbc6a14972..4a8f053234e 100644 --- a/gcc/testsuite/g++.dg/cpp0x/decltype-33837.C +++ b/gcc/testsuite/g++.dg/cpp0x/decltype-33837.C @@ -2,6 +2,6 @@ // PR c++/33837 void foo() { - __decltype (A::foo()); // { dg-error "was not declared|expected" } - __decltype (B); // { dg-error "was not declared" } + __decltype (A::foo()); // { dg-error "A" } + __decltype (B); // { dg-error "B" } } diff --git a/gcc/testsuite/g++.dg/cpp0x/decltype43.C b/gcc/testsuite/g++.dg/cpp0x/decltype43.C index 4df95a1047c..7a1dcbf8744 100644 --- a/gcc/testsuite/g++.dg/cpp0x/decltype43.C +++ b/gcc/testsuite/g++.dg/cpp0x/decltype43.C @@ -22,6 +22,6 @@ struct B int main() { int x = B::a(1))>::b(A::a(1)); - int y = B::b(A::a(2)); // { dg-error "template argument" } + int y = B::b(A::a(2)); // { dg-error "template" } return x + y; } diff --git a/gcc/testsuite/g++.dg/cpp1y/var-templ59.C b/gcc/testsuite/g++.dg/cpp1y/var-templ59.C new file mode 100644 index 00000000000..da9710e1ce4 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp1y/var-templ59.C @@ -0,0 +1,14 @@ +// PR c++/71569 +// { dg-do compile { target c++14 } } + +template +struct A { + template + static U u; +}; + +int main() +{ + decltype(A::u) a; // { dg-error "missing template arguments" } + return a; +} -- 2.30.2