public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* PR c++/5645 gcc warns that pure virtual class not explicitly initialized
@ 2007-10-27 18:03 Manuel López-Ibáñez
  2007-11-04 23:41 ` Mark Mitchell
  0 siblings, 1 reply; 13+ messages in thread
From: Manuel López-Ibáñez @ 2007-10-27 18:03 UTC (permalink / raw)
  To: GCC Patches

[-- 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,

^ permalink raw reply	[flat|nested] 13+ messages in thread

end of thread, other threads:[~2008-02-13 11:29 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-10-27 18:03 PR c++/5645 gcc warns that pure virtual class not explicitly initialized Manuel López-Ibáñez
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

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).