From: Jason Merrill Date: Wed, 28 Jun 2017 19:41:49 +0000 (-0400) Subject: PR c++/55639 - partial specialization with ::template X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=4516a545864a489d573c4c3aca498edd849899ad;p=gcc.git PR c++/55639 - partial specialization with ::template * parser.c (cp_parser_class_head): Handle ::template. From-SVN: r249754 --- diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 7b7070adf9c..f4b93ca7d10 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,5 +1,8 @@ 2017-06-28 Jason Merrill + PR c++/55639 - partial specialization with ::template + * parser.c (cp_parser_class_head): Handle ::template. + PR c++/45976 - error with ::template in declarator. * pt.c (resolve_typename_type): Fix TEMPLATE_ID_EXPR handling. diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c index c9fc2844b7f..bd99c051340 100644 --- a/gcc/cp/parser.c +++ b/gcc/cp/parser.c @@ -22602,6 +22602,9 @@ cp_parser_class_head (cp_parser* parser, /*is_declaration=*/false); /* If there was a nested-name-specifier, then there *must* be an identifier. */ + + cp_token *bad_template_keyword = NULL; + if (nested_name_specifier) { type_start_token = cp_lexer_peek_token (parser->lexer); @@ -22623,6 +22626,8 @@ cp_parser_class_head (cp_parser* parser, class-name is a template-id; if we looked for the template-name first we would stop after the template-name. */ cp_parser_parse_tentatively (parser); + if (cp_lexer_next_token_is_keyword (parser->lexer, RID_TEMPLATE)) + bad_template_keyword = cp_lexer_consume_token (parser->lexer); type = cp_parser_class_name (parser, /*typename_keyword_p=*/false, /*template_keyword_p=*/false, @@ -22742,6 +22747,12 @@ cp_parser_class_head (cp_parser* parser, { tree scope; + if (bad_template_keyword) + /* [temp.names]: in a qualified-id formed by a class-head-name, the + keyword template shall not appear at the top level. */ + pedwarn (bad_template_keyword->location, OPT_Wpedantic, + "keyword % not allowed in class-head-name"); + /* Reject typedef-names in class heads. */ if (!DECL_IMPLICIT_TYPEDEF_P (type)) { diff --git a/gcc/testsuite/g++.dg/template/partial-specialization8.C b/gcc/testsuite/g++.dg/template/partial-specialization8.C new file mode 100644 index 00000000000..e3ffe3b58a7 --- /dev/null +++ b/gcc/testsuite/g++.dg/template/partial-specialization8.C @@ -0,0 +1,19 @@ +// PR c++/55639 + +template +struct SomeClass +{ + SomeClass() { } + + template + struct Fun { + static void + fun() { } + }; +}; + +template +template +struct SomeClass::template Fun { // { dg-error "template" } + static void fun() { } +};