diff options
author | Jason Merrill <jason@redhat.com> | 2011-05-27 00:01:46 -0400 |
---|---|---|
committer | Jason Merrill <jason@gcc.gnu.org> | 2011-05-27 00:01:46 -0400 |
commit | 7c999b5781074ab69ec3604b13017625197872a9 (patch) | |
tree | a110f301d7082068a3ed15d57a08a467657c445a /gcc/cp | |
parent | 8fd1dd1461e89d9d4b44e6f9615fbca288ec40f8 (diff) | |
download | gcc-7c999b5781074ab69ec3604b13017625197872a9.zip gcc-7c999b5781074ab69ec3604b13017625197872a9.tar.gz gcc-7c999b5781074ab69ec3604b13017625197872a9.tar.bz2 |
re PR c++/47956 ([C++0x] gcc accepts static data member declaration with initializer for non-const literal type if type-specifier is auto)
PR c++/47956
* decl.c (check_static_variable_definition): Now static.
(cp_finish_decl): Call it here.
(grokdeclarator): Not here.
* pt.c (instantiate_class_template_1): Or here.
* cp-tree.h: Don't declare it.
From-SVN: r174317
Diffstat (limited to 'gcc/cp')
-rw-r--r-- | gcc/cp/ChangeLog | 9 | ||||
-rw-r--r-- | gcc/cp/cp-tree.h | 1 | ||||
-rw-r--r-- | gcc/cp/decl.c | 27 | ||||
-rw-r--r-- | gcc/cp/pt.c | 2 |
4 files changed, 20 insertions, 19 deletions
diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 605289f..577273d 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,12 @@ +2011-05-26 Jason Merrill <jason@redhat.com> + + PR c++/47956 + * decl.c (check_static_variable_definition): Now static. + (cp_finish_decl): Call it here. + (grokdeclarator): Not here. + * pt.c (instantiate_class_template_1): Or here. + * cp-tree.h: Don't declare it. + 2011-05-26 Janis Johnson <janis187@us.ibm.com> Nathan Froyd <froydnj@codesourcery.com> diff --git a/gcc/cp/cp-tree.h b/gcc/cp/cp-tree.h index ada01fb..a01253e 100644 --- a/gcc/cp/cp-tree.h +++ b/gcc/cp/cp-tree.h @@ -4895,7 +4895,6 @@ extern void finish_stmt (void); extern tree static_fn_type (tree); extern void revert_static_member_fn (tree); extern void fixup_anonymous_aggr (tree); -extern int check_static_variable_definition (tree, tree); extern tree compute_array_index_type (tree, tree, tsubst_flags_t); extern tree check_default_argument (tree, tree); typedef int (*walk_namespaces_fn) (tree, void *); diff --git a/gcc/cp/decl.c b/gcc/cp/decl.c index a956dbb..a524880 100644 --- a/gcc/cp/decl.c +++ b/gcc/cp/decl.c @@ -74,6 +74,7 @@ static void push_local_name (tree); static tree grok_reference_init (tree, tree, tree, tree *); static tree grokvardecl (tree, tree, const cp_decl_specifier_seq *, int, int, tree); +static int check_static_variable_definition (tree, tree); static void record_unknown_type (tree, const char *); static tree builtin_function_1 (tree, tree, bool); static tree build_library_fn_1 (tree, enum tree_code, tree); @@ -5909,6 +5910,7 @@ cp_finish_decl (tree decl, tree init, bool init_const_expr_p, if (current_class_type && CP_DECL_CONTEXT (decl) == current_class_type && TYPE_BEING_DEFINED (current_class_type) + && !CLASSTYPE_TEMPLATE_INSTANTIATION (current_class_type) && (DECL_INITIAL (decl) || init)) DECL_INITIALIZED_IN_CLASS_P (decl) = 1; @@ -5939,6 +5941,11 @@ cp_finish_decl (tree decl, tree init, bool init_const_expr_p, if (!ensure_literal_type_for_constexpr_object (decl)) DECL_DECLARED_CONSTEXPR_P (decl) = 0; + if (TREE_CODE (decl) == VAR_DECL + && DECL_CLASS_SCOPE_P (decl) + && DECL_INITIALIZED_IN_CLASS_P (decl)) + check_static_variable_definition (decl, type); + if (init && TREE_CODE (decl) == FUNCTION_DECL) { tree clone; @@ -7640,9 +7647,12 @@ build_ptrmem_type (tree class_type, tree member_type) messages. Return 1 if the definition is particularly bad, or 0 otherwise. */ -int +static int check_static_variable_definition (tree decl, tree type) { + /* Can't check yet if we don't know the type. */ + if (dependent_type_p (type)) + return 0; /* If DECL is declared constexpr, we'll do the appropriate checks in check_initializer. */ if (DECL_P (decl) && DECL_DECLARED_CONSTEXPR_P (decl)) @@ -10025,21 +10035,6 @@ grokdeclarator (const cp_declarator *declarator, staticp = 1; } } - - if (uses_template_parms (type)) - /* We'll check at instantiation time. */ - ; - else if (constexpr_p) - /* constexpr has the same requirements. */ - ; - else if (check_static_variable_definition (unqualified_id, - type)) - /* If we just return the declaration, crashes - will sometimes occur. We therefore return - void_type_node, as if this was a friend - declaration, to cause callers to completely - ignore this declaration. */ - return error_mark_node; } if (staticp) diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c index ab48c8f..3b26700 100644 --- a/gcc/cp/pt.c +++ b/gcc/cp/pt.c @@ -8414,8 +8414,6 @@ instantiate_class_template_1 (tree type) /*init_const_expr_p=*/false, /*asmspec_tree=*/NULL_TREE, /*flags=*/0); - if (DECL_INITIALIZED_IN_CLASS_P (r)) - check_static_variable_definition (r, TREE_TYPE (r)); } else if (TREE_CODE (r) == FIELD_DECL) { |