diff options
author | paolo <paolo@138bc75d-0d04-0410-961f-82ee72b054a4> | 2012-10-15 19:13:41 +0000 |
---|---|---|
committer | paolo <paolo@138bc75d-0d04-0410-961f-82ee72b054a4> | 2012-10-15 19:13:41 +0000 |
commit | a7351d0489d646a3774467b92a7a83e1a7d184c1 (patch) | |
tree | 2554b65829608295857311aa6a0f6c9aa8133161 /gcc/cp | |
parent | 8189de5b2463ad4343a1728b850c8f62a2f3fd07 (diff) | |
download | gcc-a7351d0489d646a3774467b92a7a83e1a7d184c1.tar.gz |
/cp
2012-10-15 Paolo Carlini <paolo.carlini@oracle.com>
PR c++/50080 (again)
* parser.c (cp_parser_optional_template_keyword): When -pedantic
and C++98 mode restore pre-Core/468 behavior.
/testsuite
2012-10-15 Paolo Carlini <paolo.carlini@oracle.com>
PR c++/50080 (again)
* g++.dg/parse/tmpl-outside2.C: Tweak, error in C++98.
* g++.dg/parse/tmpl-outside1.C: Likewise.
* g++.dg/template/qualttp18.C: Likewise.
* g++.old-deja/g++.pt/memtemp87.C: Likewise.
* g++.old-deja/g++.pt/overload13.C: Likewise.
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@192470 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'gcc/cp')
-rw-r--r-- | gcc/cp/ChangeLog | 6 | ||||
-rw-r--r-- | gcc/cp/parser.c | 26 |
2 files changed, 29 insertions, 3 deletions
diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 5239e7e33cf..555345f58a8 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,5 +1,11 @@ 2012-10-15 Paolo Carlini <paolo.carlini@oracle.com> + PR c++/50080 (again) + * parser.c (cp_parser_optional_template_keyword): When -pedantic + and C++98 mode restore pre-Core/468 behavior. + +2012-10-15 Paolo Carlini <paolo.carlini@oracle.com> + PR c++/50080 * parser.c (cp_parser_optional_template_keyword): Implement Core/468, allow outside template. diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c index 965bc621277..853d789f987 100644 --- a/gcc/cp/parser.c +++ b/gcc/cp/parser.c @@ -23252,9 +23252,29 @@ cp_parser_optional_template_keyword (cp_parser *parser) { if (cp_lexer_next_token_is_keyword (parser->lexer, RID_TEMPLATE)) { - /* Consume the `template' keyword. */ - cp_lexer_consume_token (parser->lexer); - return true; + /* In C++98 the `template' keyword can only be used within templates; + outside templates the parser can always figure out what is a + template and what is not. In C++11, per the resolution of DR 468, + `template' is allowed in cases where it is not strictly necessary. */ + if (!processing_template_decl + && pedantic && cxx_dialect == cxx98) + { + cp_token *token = cp_lexer_peek_token (parser->lexer); + pedwarn (token->location, OPT_Wpedantic, + "in C++98 %<template%> (as a disambiguator) is only " + "allowed within templates"); + /* If this part of the token stream is rescanned, the same + error message would be generated. So, we purge the token + from the stream. */ + cp_lexer_purge_token (parser->lexer); + return false; + } + else + { + /* Consume the `template' keyword. */ + cp_lexer_consume_token (parser->lexer); + return true; + } } return false; } |