From: "Manuel López-Ibáñez" <lopezibanez@gmail.com>
To: "GCC Patches" <gcc-patches@gcc.gnu.org>
Subject: PR c++/5645 gcc warns that pure virtual class not explicitly initialized
Date: Sat, 27 Oct 2007 18:03:00 -0000 [thread overview]
Message-ID: <6c33472e0710271010s2a6cc785w1524bbf39b9f607a@mail.gmail.com> (raw)
[-- Attachment #1: Type: text/plain, Size: 485 bytes --]
:ADDPATCH c++:
The patch below avoids this warning by checking for nearly emptiness.
I am not sure that this is the correct approach for 100% cases, since
I ignore all specific cases that should be warned and that shouldn't.
Bootstrapped and regression tested.
OK to commit?
Cheers,
Manuel.
2007-10-27 Manuel Lopez-Ibanez <manu@gcc.gnu.org>
PR c++/5645
* init.c (emit_mem_initializers): Don't warn if the base class is nearly empty.
testsuite/
* g++.dg/warn/pr5645.C: New.
[-- Attachment #2: fix-pr5645.diff --]
[-- Type: text/plain, Size: 1679 bytes --]
Index: gcc/testsuite/g++.dg/warn/pr5645.C
===================================================================
--- gcc/testsuite/g++.dg/warn/pr5645.C (revision 0)
+++ gcc/testsuite/g++.dg/warn/pr5645.C (revision 0)
@@ -0,0 +1,24 @@
+// PR5645: gcc warns that pure virtual class not explicitly initialized.
+// { dg-do compile }
+// { dg-options "-Wall -Wextra" }
+
+class a {
+public:
+ virtual int f() = 0;
+ virtual int g() = 0;
+};
+
+class b : public a {
+public:
+ b();
+ b(const b& c);
+
+protected:
+ int i;
+};
+
+b::b() {}
+
+b::b(const b& c) { // { dg-bogus "base class .class a. should be explicitly initialized in the copy constructor" }
+ i = c.i;
+}
Index: gcc/cp/init.c
===================================================================
--- gcc/cp/init.c (revision 128976)
+++ gcc/cp/init.c (working copy)
@@ -682,14 +682,15 @@ emit_mem_initializers (tree mem_inits)
tree subobject = TREE_PURPOSE (mem_inits);
tree arguments = TREE_VALUE (mem_inits);
/* If these initializations are taking place in a copy
constructor, the base class should probably be explicitly
- initialized. */
+ initialized unless it is nearly empty. */
if (extra_warnings && !arguments
&& DECL_COPY_CONSTRUCTOR_P (current_function_decl)
- && TYPE_NEEDS_CONSTRUCTING (BINFO_TYPE (subobject)))
+ && TYPE_NEEDS_CONSTRUCTING (BINFO_TYPE (subobject))
+ && !CLASSTYPE_NEARLY_EMPTY_P (BINFO_TYPE (subobject)))
warning (OPT_Wextra, "%Jbase class %q#T should be explicitly initialized in the "
"copy constructor",
current_function_decl, BINFO_TYPE (subobject));
/* If an explicit -- but empty -- initializer list was present,
next reply other threads:[~2007-10-27 17:10 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-10-27 18:03 Manuel López-Ibáñez [this message]
2007-11-04 23:41 ` Mark Mitchell
2007-11-05 7:21 ` Nathan Sidwell
2007-11-05 14:39 ` Jason Merrill
2007-11-12 1:33 ` Manuel López-Ibáñez
2007-11-12 4:35 ` Mark Mitchell
2007-11-12 22:05 ` Jason Merrill
2007-11-13 6:17 ` Manuel López-Ibáñez
2007-11-13 19:03 ` Jason Merrill
2007-11-14 0:22 ` Manuel López-Ibáñez
2007-11-14 22:56 ` Jason Merrill
2008-02-12 15:24 ` Jason Merrill
2008-02-13 11:42 ` Manuel López-Ibáñez
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=6c33472e0710271010s2a6cc785w1524bbf39b9f607a@mail.gmail.com \
--to=lopezibanez@gmail.com \
--cc=gcc-patches@gcc.gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).