typeck2.c (process_init_constructor): Check TREE_HAS_CONSTRUCTOR before issuing missi...
authorNathan Sidwell <nathan@codesourcery.com>
Mon, 12 Feb 2001 15:09:01 +0000 (15:09 +0000)
committerNathan Sidwell <nathan@gcc.gnu.org>
Mon, 12 Feb 2001 15:09:01 +0000 (15:09 +0000)
cp:
* typeck2.c (process_init_constructor): Check
TREE_HAS_CONSTRUCTOR before issuing missing init warning.
testsuite:
* g++.old-deja/g++.other/warn5.C: New test.

From-SVN: r39605

gcc/cp/ChangeLog
gcc/cp/typeck2.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.old-deja/g++.other/warn5.C [new file with mode: 0644]

index d1685b38ea8b2e2b5fbd66ed312343d7ba6ae33d..e2c1a8842106a6c76da2b072a6ce05519ba15390 100644 (file)
@@ -1,3 +1,8 @@
+2001-02-12  Nathan Sidwell  <nathan@codesourcery.com>
+
+       * typeck2.c (process_init_constructor): Check
+       TREE_HAS_CONSTRUCTOR before issuing missing init warning.
+
 2001-02-12  Nathan Sidwell  <nathan@codesourcery.com>
 
        * pt.c (maybe_adjust_types_for_deduction, DEDUCE_ORDER case):
index c62949ef405bff3734456e77aef83e67180a77d1..1538944ab5cecdcf9815fffaaaee22368e37d876 100644 (file)
@@ -814,12 +814,18 @@ process_init_constructor (type, init, elts)
                next1 = build_functional_cast (TREE_TYPE (field),
                                               NULL_TREE);
              else
-               next1 = build (CONSTRUCTOR, NULL_TREE, NULL_TREE,
-                              NULL_TREE);
+               {
+                 next1 = build (CONSTRUCTOR, NULL_TREE, NULL_TREE,
+                                NULL_TREE);
+                  if (init)
+                    TREE_HAS_CONSTRUCTOR (next1)
+                       = TREE_HAS_CONSTRUCTOR (init);
+                }
              next1 = digest_init (TREE_TYPE (field), next1, 0);
 
              /* Warn when some struct elements are implicitly initialized.  */
-             if (extra_warnings)
+             if (extra_warnings
+                 && (!init || TREE_HAS_CONSTRUCTOR (init)))
                cp_warning ("missing initializer for member `%D'", field);
            }
          else
@@ -835,7 +841,8 @@ process_init_constructor (type, init, elts)
 
              /* Warn when some struct elements are implicitly initialized
                 to zero.  */
-             if (extra_warnings)
+             if (extra_warnings
+                 && (!init || TREE_HAS_CONSTRUCTOR (init)))
                cp_warning ("missing initializer for member `%D'", field);
 
              /* The default zero-initialization is fine for us; don't
index 4607aa8f6d27d748df62efca2b6195ef3f899788..739250652acdfd2fb59ed36df22da51b541a0437 100644 (file)
@@ -1,3 +1,7 @@
+2001-02-12  Nathan Sidwell  <nathan@codesourcery.com>
+
+       * g++.old-deja/g++.other/warn5.C: New test.
+
 2001-02-12  Nathan Sidwell  <nathan@codesourcery.com>
 
        * g++.old-deja/g++.pt/spec40.C: New test.
diff --git a/gcc/testsuite/g++.old-deja/g++.other/warn5.C b/gcc/testsuite/g++.old-deja/g++.other/warn5.C
new file mode 100644 (file)
index 0000000..4c17dc6
--- /dev/null
@@ -0,0 +1,19 @@
+// Special g++ Options: -W 
+// Build don't link:
+// 
+// Copyright (C) 2000 Free Software Foundation, Inc.
+// Contributed by Nathan Sidwell 6 Febs 2001 <nathan@codesourcery.com>
+
+// Bug 1765. We gave bogus warning on default initializer.
+
+struct X
+{
+  int i;
+};
+
+X *foo ()
+{
+  return new X ();  // gets bogus warning
+}
+
+X x = {};           // WARNING - missing initializer