commit bef4c2fc9c89825503ddbff062544dd7d2582ac2 Author: Jason Merrill Date: Wed Jun 28 12:41:34 2017 -0400 PR c++/55639 - partial specialization with ::template * parser.c (cp_parser_class_head): Handle ::template. diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c index c9fc284..bd99c05 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 0000000..e3ffe3b --- /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() { } +};