]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
backport: re PR c++/14401 (Uninitialized reference error not reported.)
authorGabriel Dos Reis <gdr@integrable-solutions.net>
Sat, 13 Mar 2004 02:31:36 +0000 (02:31 +0000)
committerGabriel Dos Reis <gdr@gcc.gnu.org>
Sat, 13 Mar 2004 02:31:36 +0000 (02:31 +0000)
        Backport:
        2004-03-08  Mark Mitchell  <mark@codesourcery.com>
        PR c++/14401
        * class.c (check_field_decls): Complain about non-static data
        members of reference type in unions.  Propagate
        CLASSTYPE_REF_FIELDS_NEED_INIT and
        CLASSTYPE_READONLY_FIELDS_NEED_INIT from the types of
        non-static
        data members.
        * init.c (perform_member_init): Complain about members with const
        type that are not explicitly initialized.

From-SVN: r79426

gcc/cp/ChangeLog
gcc/cp/class.c
gcc/cp/init.c

index 762f1472b19d6421ea0d86ba234bf0b95fdd84f4..cf29f936899de2300c3730cbff1a4f203ffd6650 100644 (file)
@@ -1,3 +1,16 @@
+2004-03-12  Gabriel Dos Reis  <gdr@integrable-solutions.net>
+
+       Backport:
+       2004-03-08  Mark Mitchell  <mark@codesourcery.com>
+       PR c++/14401
+       * class.c (check_field_decls): Complain about non-static data
+       members of reference type in unions.  Propagate
+       CLASSTYPE_REF_FIELDS_NEED_INIT and
+       CLASSTYPE_READONLY_FIELDS_NEED_INIT from the types of non-static
+       data members.
+       * init.c (perform_member_init): Complain about members with const
+       type that are not explicitly initialized.
+
 2004-03-12  Gabriel Dos Reis  <gdr@integrable-solutions.net>
 
        Backport:
index 3546743f215c09f08306da2aae8e698aee2afdae..0c5ace708f2a2b958e94d5f99bbd4d2ac01da6fa 100644 (file)
@@ -3231,9 +3231,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);
@@ -3263,21 +3284,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))
@@ -3308,6 +3317,14 @@ check_field_decls (tree t, tree *access_decls,
       if (TREE_CODE (type) == POINTER_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;
 
index 70085280290b9d12e2141cf8baa433c87085f47e..f3fa9aa93f792f41a1321206d6f6cf297f064270 100644 (file)
@@ -390,6 +390,9 @@ perform_member_init (tree member, tree init)
          /* member traversal: note it leaves init NULL */
          else if (TREE_CODE (type) == REFERENCE_TYPE)
            pedwarn ("uninitialized reference member `%D'", member);
+          else if (CP_TYPE_CONST_P (type))
+            pedwarn ("uninitialized member '%D' with 'const' type '%T'",
+                     member, type);
        }
       else if (TREE_CODE (init) == TREE_LIST)
        {