public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/11159] erroneous warning in copy ctor with virtual inheritance
       [not found] <bug-11159-5779@http.gcc.gnu.org/bugzilla/>
@ 2006-03-09 22:44 ` wotte at dre dot vanderbilt dot edu
  2006-04-04 12:26 ` roman dot fietze at telemotive dot de
                   ` (6 subsequent siblings)
  7 siblings, 0 replies; 12+ messages in thread
From: wotte at dre dot vanderbilt dot edu @ 2006-03-09 22:44 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #9 from wotte at dre dot vanderbilt dot edu  2006-03-09 22:44 -------
In some cases, this warning can also be impossible to address and may be
buggy/erroneous.  Consider the following example:
========
struct A
{
  A ();
};

struct B : virtual A
{
  B ();
};

struct C :  virtual B
{
  C ();
};

template <typename Base>
struct E : Base
{
  E ();

  E (E const &)
  {
  };
};

E<C> foo;
E<C> bar (foo);
====
Produces the following diagnostic:

test.cpp: In copy constructor 'E<Base>::E(const E<Base>&) [with Base = C]':
test.cpp:27:   instantiated from here
test.cpp:21: warning: base class 'struct A' should be explicitly initialized in
the copy constructor
test.cpp:21: warning: base class 'struct B' should be explicitly initialized in
the copy constructor
test.cpp:21: warning: base class 'struct C' should be explicitly initialized in
the copy constructor

If I make an immediately obvious fix by explicitly initializing Base:

========
struct A
{
  A ();
};

struct B : virtual A
{
  B ();
};

struct C :  virtual B
{
  C ();
};

template <typename Base>
struct E : Base
{
  E ();

  E (E const &)
    : Base ()
  {
  };
};

E<C> foo;
E<C> bar (foo);

====

I am presented with the following diagnostic:
test.cpp: In copy constructor 'E<Base>::E(const E<Base>&) [with Base = C]':
test.cpp:28:   instantiated from here
test.cpp:21: warning: base class 'struct A' should be explicitly initialized in
the copy constructor
test.cpp:21: warning: base class 'struct B' should be explicitly initialized in
the copy constructor

In this case, E can't explicitly initialize A or B, because E can't assume that
either is present as a parent of Base.  This is also likely erroneous because E
shouldn't have to explicitly initialize the parents of Base... That should be
handled by the copy constructor of Base.


-- 

wotte at dre dot vanderbilt dot edu changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |wotte at dre dot vanderbilt
                   |                            |dot edu


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=11159


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

* [Bug c++/11159] erroneous warning in copy ctor with virtual inheritance
       [not found] <bug-11159-5779@http.gcc.gnu.org/bugzilla/>
  2006-03-09 22:44 ` [Bug c++/11159] erroneous warning in copy ctor with virtual inheritance wotte at dre dot vanderbilt dot edu
@ 2006-04-04 12:26 ` roman dot fietze at telemotive dot de
  2007-01-09 14:50 ` manu at gcc dot gnu dot org
                   ` (5 subsequent siblings)
  7 siblings, 0 replies; 12+ messages in thread
From: roman dot fietze at telemotive dot de @ 2006-04-04 12:26 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #10 from roman dot fietze at telemotive dot de  2006-04-04 12:26 -------
The following snippet also gives me errors, and here, as a developer, I did all
I could do:
-----
#include <sstream>
class MyStream : public std::ostringstream
{
  public:
    inline MyStream() : std::ostringstream() {}
    inline MyStream(const MyStream &ms) : std::ostringstream()
        { std::ostringstream::str(ms.str()); }
};
-----

The result, as before:

$ gcc --version
gcc (GCC) 3.3.5 20050117 (prerelease) (SUSE Linux)
...
$ g++ -W -c mystream.cc
mystream.cc: In copy constructor `MyStream::MyStream(const MyStream&)':
mystream.cc:13: warning: base class `struct std::basic_ios<char, 
   std::char_traits<char> >' should be explicitly initialized in the copy 
   constructor

I do not have access to std::basic_ios from MyStream. Solution here?


-- 

roman dot fietze at telemotive dot de changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |roman dot fietze at
                   |                            |telemotive dot de


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=11159


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

* [Bug c++/11159] erroneous warning in copy ctor with virtual inheritance
       [not found] <bug-11159-5779@http.gcc.gnu.org/bugzilla/>
  2006-03-09 22:44 ` [Bug c++/11159] erroneous warning in copy ctor with virtual inheritance wotte at dre dot vanderbilt dot edu
  2006-04-04 12:26 ` roman dot fietze at telemotive dot de
@ 2007-01-09 14:50 ` manu at gcc dot gnu dot org
  2007-02-09 14:03 ` manu at gcc dot gnu dot org
                   ` (4 subsequent siblings)
  7 siblings, 0 replies; 12+ messages in thread
From: manu at gcc dot gnu dot org @ 2007-01-09 14:50 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #11 from manu at gcc dot gnu dot org  2007-01-09 14:50 -------
There is an unreviewed patch to name this warning in the patch queue:
http://gcc.gnu.org/ml/gcc-patches/2007-01/msg00520.html

I guess it doesn't solve all the inconsistencies mentioned here but at least it
can be individually disable.

Also, it could have better testcases and perhaps an apter name: feedback is
always welcome.


-- 

manu at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |manu at gcc dot gnu dot org


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=11159


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

* [Bug c++/11159] erroneous warning in copy ctor with virtual inheritance
       [not found] <bug-11159-5779@http.gcc.gnu.org/bugzilla/>
                   ` (2 preceding siblings ...)
  2007-01-09 14:50 ` manu at gcc dot gnu dot org
@ 2007-02-09 14:03 ` manu at gcc dot gnu dot org
  2007-11-14 13:27 ` jwakely dot gcc at gmail dot com
                   ` (3 subsequent siblings)
  7 siblings, 0 replies; 12+ messages in thread
From: manu at gcc dot gnu dot org @ 2007-02-09 14:03 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #12 from manu at gcc dot gnu dot org  2007-02-09 14:03 -------
Also related to this warning: PR 5645.


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=11159


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

* [Bug c++/11159] erroneous warning in copy ctor with virtual inheritance
       [not found] <bug-11159-5779@http.gcc.gnu.org/bugzilla/>
                   ` (3 preceding siblings ...)
  2007-02-09 14:03 ` manu at gcc dot gnu dot org
@ 2007-11-14 13:27 ` jwakely dot gcc at gmail dot com
  2007-11-16 13:59 ` manu at gcc dot gnu dot org
                   ` (2 subsequent siblings)
  7 siblings, 0 replies; 12+ messages in thread
From: jwakely dot gcc at gmail dot com @ 2007-11-14 13:27 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #13 from jwakely dot gcc at gmail dot com  2007-11-14 13:27 -------
(In reply to comment #10)
> 
> I do not have access to std::basic_ios from MyStream. Solution here?

Yes you do.  The warning can be prevented by initialising the virtual base:

    MyStream() : std::ios(), std::ostringstream() {} 

However in general I agree that the warnings are bogus. If there is no suitable
constructor for the virtual base you get an error, so the warning is only
issued when the behaviour is perfectly well-defined, and in many cases probably
exactly what the author of the code wanted.

Even the text of the warning is misleading. Why "should" it be explicitly
initialised, when the standard says it will be implicitly initialised if a
suitable default constructor exists?

If you want to use a non-default constructor for the virtual base then you need
to call it explicitly. But if the default constructor is what you want, why
should you have to do extra work?


-- 

jwakely dot gcc at gmail dot com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |jwakely dot gcc at gmail dot
                   |                            |com


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=11159


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

* [Bug c++/11159] erroneous warning in copy ctor with virtual inheritance
       [not found] <bug-11159-5779@http.gcc.gnu.org/bugzilla/>
                   ` (4 preceding siblings ...)
  2007-11-14 13:27 ` jwakely dot gcc at gmail dot com
@ 2007-11-16 13:59 ` manu at gcc dot gnu dot org
  2008-02-13 11:13 ` manu at gcc dot gnu dot org
  2008-02-14 23:12 ` jason at gcc dot gnu dot org
  7 siblings, 0 replies; 12+ messages in thread
From: manu at gcc dot gnu dot org @ 2007-11-16 13:59 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #14 from manu at gcc dot gnu dot org  2007-11-16 13:58 -------
(In reply to comment #13)
> Even the text of the warning is misleading. Why "should" it be explicitly
> initialised, when the standard says it will be implicitly initialised if a
> suitable default constructor exists?
> 
> If you want to use a non-default constructor for the virtual base then you need
> to call it explicitly. But if the default constructor is what you want, why
> should you have to do extra work?
> 

I wonder as well. Removing this warning will close at least two PRs...


-- 

manu at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Last reconfirmed|2005-12-11 23:10:09         |2007-11-16 13:58:57
               date|                            |


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=11159


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

* [Bug c++/11159] erroneous warning in copy ctor with virtual inheritance
       [not found] <bug-11159-5779@http.gcc.gnu.org/bugzilla/>
                   ` (5 preceding siblings ...)
  2007-11-16 13:59 ` manu at gcc dot gnu dot org
@ 2008-02-13 11:13 ` manu at gcc dot gnu dot org
  2008-02-14 23:12 ` jason at gcc dot gnu dot org
  7 siblings, 0 replies; 12+ messages in thread
From: manu at gcc dot gnu dot org @ 2008-02-13 11:13 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #15 from manu at gcc dot gnu dot org  2008-02-13 11:13 -------
I am going to close this as a duplicate of 5645 and post a patch there that
includes the testcases of both PRs. Both bugs are about the definition (or lack
of it) of this warning.

*** This bug has been marked as a duplicate of 5645 ***


-- 

manu at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|                            |DUPLICATE


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=11159


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

* [Bug c++/11159] erroneous warning in copy ctor with virtual inheritance
       [not found] <bug-11159-5779@http.gcc.gnu.org/bugzilla/>
                   ` (6 preceding siblings ...)
  2008-02-13 11:13 ` manu at gcc dot gnu dot org
@ 2008-02-14 23:12 ` jason at gcc dot gnu dot org
  7 siblings, 0 replies; 12+ messages in thread
From: jason at gcc dot gnu dot org @ 2008-02-14 23:12 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #16 from jason at gcc dot gnu dot org  2008-02-14 23:11 -------
Subject: Bug 11159

Author: jason
Date: Thu Feb 14 23:11:04 2008
New Revision: 132324

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=132324
Log:
        PR c++/5645
        PR c++/11159
        * class.c (type_has_user_nondefault_constructor): New fn.
        * cp-tree.h: Declare it.
        * init.c (emit_mem_initializers): Use it for -W warning about
        missing base initializer.

Added:
    trunk/gcc/testsuite/g++.dg/warn/pr11159.C
    trunk/gcc/testsuite/g++.dg/warn/pr5645.C
Modified:
    trunk/gcc/cp/ChangeLog
    trunk/gcc/cp/class.c
    trunk/gcc/cp/cp-tree.h
    trunk/gcc/cp/init.c
    trunk/gcc/testsuite/g++.dg/warn/Wreorder-1.C


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=11159


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

* [Bug c++/11159] erroneous warning in copy ctor with virtual inheritance
  2003-06-11 19:08 [Bug c++/11159] New: errornous " boris@kolpackov.net
                   ` (2 preceding siblings ...)
  2004-04-27  3:03 ` pinskia at gcc dot gnu dot org
@ 2004-10-01 16:42 ` ns at fluent dot com
  3 siblings, 0 replies; 12+ messages in thread
From: ns at fluent dot com @ 2004-10-01 16:42 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From ns at fluent dot com  2004-10-01 16:42 -------
It would be very useful to be able to specifically
suppress this warning message - 3rd party headers
are downing out the more useful information in 
our build logs.

-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=11159


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

* [Bug c++/11159] erroneous warning in copy ctor with virtual inheritance
  2003-06-11 19:08 [Bug c++/11159] New: errornous " boris@kolpackov.net
  2003-08-04 20:55 ` [Bug c++/11159] erroneous " pinskia at physics dot uc dot edu
  2004-04-26 19:55 ` pinskia at gcc dot gnu dot org
@ 2004-04-27  3:03 ` pinskia at gcc dot gnu dot org
  2004-10-01 16:42 ` ns at fluent dot com
  3 siblings, 0 replies; 12+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2004-04-27  3:03 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From pinskia at gcc dot gnu dot org  2004-04-27 01:55 -------
*** Bug 11804 has been marked as a duplicate of this bug. ***

-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |nicolas dot burrus at lrde
                   |                            |dot epita dot fr


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=11159


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

* [Bug c++/11159] erroneous warning in copy ctor with virtual inheritance
  2003-06-11 19:08 [Bug c++/11159] New: errornous " boris@kolpackov.net
  2003-08-04 20:55 ` [Bug c++/11159] erroneous " pinskia at physics dot uc dot edu
@ 2004-04-26 19:55 ` pinskia at gcc dot gnu dot org
  2004-04-27  3:03 ` pinskia at gcc dot gnu dot org
  2004-10-01 16:42 ` ns at fluent dot com
  3 siblings, 0 replies; 12+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2004-04-26 19:55 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From pinskia at gcc dot gnu dot org  2004-04-26 19:46 -------
Your last example does not give a warning on 2.95.3, 3.0.4, 3.2.3, 3.3.3, 3.4.0 or the 
mainline.

Your first example still gives a warning on the mainline.

-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
   Last reconfirmed|2003-11-29 21:00:39         |2004-04-26 19:46:32
               date|                            |


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=11159


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

* [Bug c++/11159] erroneous warning in copy ctor with virtual inheritance
  2003-06-11 19:08 [Bug c++/11159] New: errornous " boris@kolpackov.net
@ 2003-08-04 20:55 ` pinskia at physics dot uc dot edu
  2004-04-26 19:55 ` pinskia at gcc dot gnu dot org
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 12+ messages in thread
From: pinskia at physics dot uc dot edu @ 2003-08-04 20:55 UTC (permalink / raw)
  To: gcc-bugs

PLEASE REPLY TO gcc-bugzilla@gcc.gnu.org ONLY, *NOT* gcc-bugs@gcc.gnu.org.

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=11159


pinskia at physics dot uc dot edu changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Target Milestone|3.4                         |---


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

end of thread, other threads:[~2008-02-14 23:12 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <bug-11159-5779@http.gcc.gnu.org/bugzilla/>
2006-03-09 22:44 ` [Bug c++/11159] erroneous warning in copy ctor with virtual inheritance wotte at dre dot vanderbilt dot edu
2006-04-04 12:26 ` roman dot fietze at telemotive dot de
2007-01-09 14:50 ` manu at gcc dot gnu dot org
2007-02-09 14:03 ` manu at gcc dot gnu dot org
2007-11-14 13:27 ` jwakely dot gcc at gmail dot com
2007-11-16 13:59 ` manu at gcc dot gnu dot org
2008-02-13 11:13 ` manu at gcc dot gnu dot org
2008-02-14 23:12 ` jason at gcc dot gnu dot org
2003-06-11 19:08 [Bug c++/11159] New: errornous " boris@kolpackov.net
2003-08-04 20:55 ` [Bug c++/11159] erroneous " pinskia at physics dot uc dot edu
2004-04-26 19:55 ` pinskia at gcc dot gnu dot org
2004-04-27  3:03 ` pinskia at gcc dot gnu dot org
2004-10-01 16:42 ` ns at fluent dot com

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