diff options
author | Mark Mitchell <mark@codesourcery.com> | 2006-02-18 08:36:11 +0000 |
---|---|---|
committer | Mark Mitchell <mmitchel@gcc.gnu.org> | 2006-02-18 08:36:11 +0000 |
commit | d174af6c5853a9adef67ed509faa51a79ad9d320 (patch) | |
tree | c096019ad738deb34504520ca833df4491508a99 /gcc/cp/parser.c | |
parent | 8305d7868da2a057825734b31113455ef97d9a76 (diff) | |
download | gcc-d174af6c5853a9adef67ed509faa51a79ad9d320.zip gcc-d174af6c5853a9adef67ed509faa51a79ad9d320.tar.gz gcc-d174af6c5853a9adef67ed509faa51a79ad9d320.tar.bz2 |
re PR c++/26266 (Trouble with static const data members in template classes)
PR c++/26266
* cp-tree.h (cp_finish_decl): Adjust declaration.
(grokbitfield): Likewise.
(finish_static_data_member_decl): Likewise.
* init.c (constant_value_1): Ensure processing_template_decl when
folding non-dependent initializers for static data members of
dependent types. Return error_mark_node for erroneous
initailizers.
* class.c (get_vtable_decl): Use finish_decl, not cp_finish_decl.
* decl.c (cp_make_fname_decl): Adjust call to cp_finish_decl.
(cp_finish_decl): Add init_const_expr_p parameter. Set
DECL_INITIALIZED_BY_CONSTANT_EXPRESSION_P here.
(finish_decl): Adjust call to cp_finish_decl.
(compute_array_index_type): Robustify.
(start_method): Use finish_decl, not cp_finish_decl.
* rtti.c (emit_tinfo_decl): Likewise.
* except.c (initialize_handler_parm): Adjust call to
cp_finish_decl.
(expand_start_catch_block): Likewise.
* cvt.c (build_up_reference): Adjust call to cp_finish_decl.
* pt.c (instantiate_class_template): Adjust call to
finish_static_data_member_decl.
(tsubst_expr): Use finish_decl, not cp_finish_decl.
(instantiate_decl): Adjust call to cp_finish_decl.
* name-lookup.c (pushdecl_top_level_1): Use finish_decl, not
cp_finish_decl.
* decl2.c (finish_static_data_member_decl): Add init_const_expr_p
parameter.
(grokfield): Likewise.
* parser.c (cp_parser_condition): Check for constant initializers.
(cp_parser_init_declarator): Adjust calls to grokfield and
cp_finish_decl. Don't set
DECL_INITIALIZED_BY_CONSTANT_EXPRESSION_P here.
(cp_parser_member_declaration): Likewise.
(cp_parser_objc_class_ivars): Likewise.
PR c++/26266
* g++.dg/template/static22.C: New test.
* g++.dg/template/static23.C: New test.
* g++.dg/template/static24.C: New test.
* g++.dg/template/non-dependent13.C: New test.
From-SVN: r111229
Diffstat (limited to 'gcc/cp/parser.c')
-rw-r--r-- | gcc/cp/parser.c | 40 |
1 files changed, 18 insertions, 22 deletions
diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c index 37df311..ffec8f2 100644 --- a/gcc/cp/parser.c +++ b/gcc/cp/parser.c @@ -6500,6 +6500,7 @@ cp_parser_condition (cp_parser* parser) if (cp_parser_parse_definitely (parser)) { tree pushed_scope; + bool non_constant_p; /* Create the declaration. */ decl = start_decl (declarator, &type_specifiers, @@ -6507,12 +6508,16 @@ cp_parser_condition (cp_parser* parser) attributes, /*prefix_attributes=*/NULL_TREE, &pushed_scope); /* Parse the assignment-expression. */ - initializer = cp_parser_assignment_expression (parser, - /*cast_p=*/false); + initializer + = cp_parser_constant_expression (parser, + /*allow_non_constant_p=*/true, + &non_constant_p); + if (!non_constant_p) + initializer = fold_non_dependent_expr (initializer); /* Process the initializer. */ cp_finish_decl (decl, - initializer, + initializer, !non_constant_p, asm_specification, LOOKUP_ONLYCONVERTING); @@ -11061,7 +11066,8 @@ cp_parser_init_declarator (cp_parser* parser, pushed_scope = false; } decl = grokfield (declarator, decl_specifiers, - initializer, /*asmspec=*/NULL_TREE, + initializer, !is_non_constant_init, + /*asmspec=*/NULL_TREE, prefix_attributes); if (decl && TREE_CODE (decl) == FUNCTION_DECL) cp_parser_save_default_args (parser, decl); @@ -11072,7 +11078,7 @@ cp_parser_init_declarator (cp_parser* parser, if (!friend_p && decl && decl != error_mark_node) { cp_finish_decl (decl, - initializer, + initializer, !is_non_constant_init, asm_specification, /* If the initializer is in parentheses, then this is a direct-initialization, which means that an @@ -11084,12 +11090,6 @@ cp_parser_init_declarator (cp_parser* parser, if (!friend_p && pushed_scope) pop_scope (pushed_scope); - /* Remember whether or not variables were initialized by - constant-expressions. */ - if (decl && TREE_CODE (decl) == VAR_DECL - && is_initialized && !is_non_constant_init) - DECL_INITIALIZED_BY_CONSTANT_EXPRESSION_P (decl) = true; - return decl; } @@ -13706,16 +13706,11 @@ cp_parser_member_declaration (cp_parser* parser) return; } else - { - /* Create the declaration. */ - decl = grokfield (declarator, &decl_specifiers, - initializer, asm_specification, - attributes); - /* Any initialization must have been from a - constant-expression. */ - if (decl && TREE_CODE (decl) == VAR_DECL && initializer) - DECL_INITIALIZED_BY_CONSTANT_EXPRESSION_P (decl) = 1; - } + /* Create the declaration. */ + decl = grokfield (declarator, &decl_specifiers, + initializer, /*init_const_expr_p=*/true, + asm_specification, + attributes); } /* Reset PREFIX_ATTRIBUTES. */ @@ -17278,7 +17273,8 @@ cp_parser_objc_class_ivars (cp_parser* parser) cplus_decl_attributes (&decl, attributes, /*flags=*/0); } else - decl = grokfield (declarator, &declspecs, NULL_TREE, + decl = grokfield (declarator, &declspecs, + NULL_TREE, /*init_const_expr_p=*/false, NULL_TREE, attributes); /* Add the instance variable. */ |