diff options
Diffstat (limited to 'gcc/cp/class.c')
-rw-r--r-- | gcc/cp/class.c | 50 |
1 files changed, 31 insertions, 19 deletions
diff --git a/gcc/cp/class.c b/gcc/cp/class.c index 3a34ce45668..eddfda80429 100644 --- a/gcc/cp/class.c +++ b/gcc/cp/class.c @@ -2923,9 +2923,30 @@ check_field_decls (tree t, tree *access_decls, /* If we've gotten this far, it's a data member, possibly static, or an enumerator. */ - DECL_CONTEXT (x) = t; + /* When this goes into scope, it will be a non-local reference. */ + DECL_NONLOCAL (x) = 1; + + if (TREE_CODE (t) == UNION_TYPE) + { + /* [class.union] + + If a union contains a static data member, or a member of + reference type, the program is ill-formed. */ + if (TREE_CODE (x) == VAR_DECL) + { + cp_error_at ("`%D' may not be static because it is a member of a union", x); + continue; + } + if (TREE_CODE (type) == REFERENCE_TYPE) + { + cp_error_at ("`%D' may not have reference type `%T' because it is a member of a union", + x, type); + continue; + } + } + /* ``A local class cannot have static data members.'' ARM 9.4 */ if (current_function_decl && TREE_STATIC (x)) cp_error_at ("field `%D' in local class cannot be static", x); @@ -2949,21 +2970,9 @@ check_field_decls (tree t, tree *access_decls, if (type == error_mark_node) continue; - /* When this goes into scope, it will be a non-local reference. */ - DECL_NONLOCAL (x) = 1; - - if (TREE_CODE (x) == CONST_DECL) + if (TREE_CODE (x) == CONST_DECL || TREE_CODE (x) == VAR_DECL) continue; - if (TREE_CODE (x) == VAR_DECL) - { - if (TREE_CODE (t) == UNION_TYPE) - /* Unions cannot have static members. */ - cp_error_at ("field `%D' declared static in union", x); - - continue; - } - /* Now it can only be a FIELD_DECL. */ if (TREE_PRIVATE (x) || TREE_PROTECTED (x)) @@ -2994,6 +3003,14 @@ check_field_decls (tree t, tree *access_decls, if (TYPE_PTR_P (type)) has_pointers = 1; + if (CLASS_TYPE_P (type)) + { + if (CLASSTYPE_REF_FIELDS_NEED_INIT (type)) + SET_CLASSTYPE_REF_FIELDS_NEED_INIT (t, 1); + if (CLASSTYPE_READONLY_FIELDS_NEED_INIT (type)) + SET_CLASSTYPE_READONLY_FIELDS_NEED_INIT (t, 1); + } + if (DECL_MUTABLE_P (x) || TYPE_HAS_MUTABLE_P (type)) CLASSTYPE_HAS_MUTABLE (t) = 1; @@ -3683,11 +3700,6 @@ check_methods (tree t) for (x = TYPE_METHODS (t); x; x = TREE_CHAIN (x)) { - /* If this was an evil function, don't keep it in class. */ - if (DECL_ASSEMBLER_NAME_SET_P (x) - && IDENTIFIER_ERROR_LOCUS (DECL_ASSEMBLER_NAME (x))) - continue; - check_for_override (x, t); if (DECL_PURE_VIRTUAL_P (x) && ! DECL_VINDEX (x)) cp_error_at ("initializer specified for non-virtual method `%D'", x); |