This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
C++ PATCH: PR 26122
- From: Mark Mitchell <mark at codesourcery dot com>
- To: gcc-patches at gcc dot gnu dot org
- Date: Tue, 11 Apr 2006 15:56:56 -0700
- Subject: C++ PATCH: PR 26122
- Reply-to: mark at codesourcery dot com
This patch fixes PR c++/26122, a case where we ICE'd on an invalid
pure specifier. There was bogus logic in the parser that compared a
boolean to CPP_EQ, which didn't make sense.
Tested on x86_64-unknown-linux-gnu, applied to mainline. I shall
backport to 4.1 forthwith, and apply there.
--
Mark Mitchell
CodeSourcery
mark@codesourcery.com
(650) 331-3385 x713
2006-04-11 Mark Mitchell <mark@codesourcery.com>
PR c++/26122
* parser.c (cp_parser_init_declarator): Adjust logic for deciding
whether or not to look for a pure-specifier.
(cp_parser_member_declaration): Likewise.
Index: gcc/cp/parser.c
===================================================================
--- gcc/cp/parser.c (revision 112844)
+++ gcc/cp/parser.c (working copy)
@@ -10887,6 +10888,10 @@ cp_parser_init_declarator (cp_parser* pa
tree decl = NULL_TREE;
tree scope;
bool is_initialized;
+ /* Only valid if IS_INITIALIZED is true. In that case, CPP_EQ if
+ initialized with "= ..", CPP_OPEN_PAREN if initialized with
+ "(...)". */
+ enum cpp_ttype initialization_kind;
bool is_parenthesized_init;
bool is_non_constant_init;
int ctor_dtor_or_conv_p;
@@ -11001,16 +11006,24 @@ cp_parser_init_declarator (cp_parser* pa
}
/* An `=' or an `(' indicates an initializer. */
- is_initialized = (token->type == CPP_EQ
- || token->type == CPP_OPEN_PAREN);
- /* If the init-declarator isn't initialized and isn't followed by a
- `,' or `;', it's not a valid init-declarator. */
- if (!is_initialized
- && token->type != CPP_COMMA
- && token->type != CPP_SEMICOLON)
+ if (token->type == CPP_EQ
+ || token->type == CPP_OPEN_PAREN)
{
- cp_parser_error (parser, "expected initializer");
- return error_mark_node;
+ is_initialized = true;
+ initialization_kind = token->type;
+ }
+ else
+ {
+ /* If the init-declarator isn't initialized and isn't followed by a
+ `,' or `;', it's not a valid init-declarator. */
+ if (token->type != CPP_COMMA
+ && token->type != CPP_SEMICOLON)
+ {
+ cp_parser_error (parser, "expected initializer");
+ return error_mark_node;
+ }
+ is_initialized = false;
+ initialization_kind = CPP_EOF;
}
/* Because start_decl has side-effects, we should only call it if we
@@ -11081,9 +11094,16 @@ cp_parser_init_declarator (cp_parser* pa
/* Parse the initializer. */
if (is_initialized)
- initializer = cp_parser_initializer (parser,
- &is_parenthesized_init,
- &is_non_constant_init);
+ {
+ if (declarator->kind == cdk_function
+ && declarator->declarator->kind == cdk_id
+ && initialization_kind == CPP_EQ)
+ initializer = cp_parser_pure_specifier (parser);
+ else
+ initializer = cp_parser_initializer (parser,
+ &is_parenthesized_init,
+ &is_non_constant_init);
+ }
else
{
initializer = NULL_TREE;
@@ -13710,7 +13736,8 @@ cp_parser_member_declaration (cp_parser*
for a pure-specifier; otherwise, we look for a
constant-initializer. When we call `grokfield', it will
perform more stringent semantics checks. */
- if (declarator->kind == cdk_function)
+ if (declarator->kind == cdk_function
+ && declarator->declarator->kind == cdk_id)
initializer = cp_parser_pure_specifier (parser);
else
/* Parse the initializer. */
Index: gcc/testsuite/g++.dg/template/pure1.C
===================================================================
--- gcc/testsuite/g++.dg/template/pure1.C (revision 0)
+++ gcc/testsuite/g++.dg/template/pure1.C (revision 0)
@@ -0,0 +1,6 @@
+// PR c++/26122
+
+struct A
+{
+ template<int> void foo() = 1; // { dg-error "pure" }
+};