From 45abaea89ceed7cbd6128a841605430da841064a Mon Sep 17 00:00:00 2001 From: Nathan Sidwell Date: Mon, 12 Feb 2001 15:09:01 +0000 Subject: [PATCH] typeck2.c (process_init_constructor): Check TREE_HAS_CONSTRUCTOR before issuing missing init warning. 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 | 5 +++++ gcc/cp/typeck2.c | 15 +++++++++++---- gcc/testsuite/ChangeLog | 4 ++++ gcc/testsuite/g++.old-deja/g++.other/warn5.C | 19 +++++++++++++++++++ 4 files changed, 39 insertions(+), 4 deletions(-) create mode 100644 gcc/testsuite/g++.old-deja/g++.other/warn5.C diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index d1685b38ea8..e2c1a884210 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,8 @@ +2001-02-12 Nathan Sidwell + + * typeck2.c (process_init_constructor): Check + TREE_HAS_CONSTRUCTOR before issuing missing init warning. + 2001-02-12 Nathan Sidwell * pt.c (maybe_adjust_types_for_deduction, DEDUCE_ORDER case): diff --git a/gcc/cp/typeck2.c b/gcc/cp/typeck2.c index c62949ef405..1538944ab5c 100644 --- a/gcc/cp/typeck2.c +++ b/gcc/cp/typeck2.c @@ -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 diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 4607aa8f6d2..739250652ac 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,7 @@ +2001-02-12 Nathan Sidwell + + * g++.old-deja/g++.other/warn5.C: New test. + 2001-02-12 Nathan Sidwell * 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 index 00000000000..4c17dc66406 --- /dev/null +++ b/gcc/testsuite/g++.old-deja/g++.other/warn5.C @@ -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 + +// 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 -- 2.30.2