public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/21917] Missing warning when trying to explicitly construct a virtual base
       [not found] <bug-21917-4@http.gcc.gnu.org/bugzilla/>
@ 2010-10-28  9:17 ` redi at gcc dot gnu.org
  0 siblings, 0 replies; 3+ messages in thread
From: redi at gcc dot gnu.org @ 2010-10-28  9:17 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #8 from Jonathan Wakely <redi at gcc dot gnu.org> 2010-10-28 09:17:23 UTC ---
I've relied on exactly this behaviour and wouldn't want a warning.

struct Base : virtual std::ios {
  Base() : std::ios(0) { }
  std::streambuf buf;
};

struct MyStream : Base, std::iostream {
  MyStream() : std::iostream(0) { }
};

If a concrete Base is constructed I want to call ios::ios(0) but if a MyStream
is constructed then I want to call the ios::ios() default ctor and then have
iostream::iostream(0) call ios::init(0)

If this warning is added (which I'm not convinced it should be) then it should
not be given if the most-derived class *explicitly* uses a different ctor for
the virtual base i.e. I could suppress the warning by changing the code above
like so:

  MyStream() : std::ios(), std::iostream(0) { }
               ^^^^^^^^^^^

I also don't think the warning should be given if the unused mem-initializer in
der1 and der2 calls the same constructor as is implicitly called by the
most-derived class, i.e. if der1 and der2 called virt() then that has the same
effect as the implicit initialization done by top.

I don't think this should be P2, and I think a better summary would be "Missing
warning when virtual base is initialized with different constructor than
requested by an ignored mem-initializer"


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

* [Bug c++/21917] Missing warning when trying to explicitly construct a virtual base
       [not found] <bug-21917-6594@http.gcc.gnu.org/bugzilla/>
  2007-01-20 16:52 ` manu at gcc dot gnu dot org
@ 2008-06-05 23:07 ` r_q_einstein-gccgnuorg at yahoo dot com
  1 sibling, 0 replies; 3+ messages in thread
From: r_q_einstein-gccgnuorg at yahoo dot com @ 2008-06-05 23:07 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #7 from r_q_einstein-gccgnuorg at yahoo dot com  2008-06-05 23:07 -------
I've run across this, too.
I agree with Ivan's 2005-06-04 suggestion.
It would be nice if the compiler would emit a warning that the derived class's
constructor's call to the virtual base class's non-default constructor is being
ignored and overridden by an implicit call to the virtual base class's default
constructor.
Similarly, if the virtual base class fails to specify a default constructor
(and specifies only a non-default one), the derived class's constructor's call
to the virtual base class's non-default constructor produces only this error
message:

In constructor 'top::top()':
 error: no matching function for call to 'virt::virt()'

which leaves the developer scratching his/her head if he doesn't know that the
C++ spec. requires virtual base classes to have default constructors.  (True,
s/he should know, but the compile error message could be more helpful.)
Something to the effect of:
"virtual base class lacks default constructor" would be much more helpful.

If this issue is different enough to warrant a separate "bug" report, let me
know and I'll be happy to file it separately.
Thanks.


-- 

r_q_einstein-gccgnuorg at yahoo dot com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |r_q_einstein-gccgnuorg at
                   |                            |yahoo dot com


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


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

* [Bug c++/21917] Missing warning when trying to explicitly construct a virtual base
       [not found] <bug-21917-6594@http.gcc.gnu.org/bugzilla/>
@ 2007-01-20 16:52 ` manu at gcc dot gnu dot org
  2008-06-05 23:07 ` r_q_einstein-gccgnuorg at yahoo dot com
  1 sibling, 0 replies; 3+ messages in thread
From: manu at gcc dot gnu dot org @ 2007-01-20 16:52 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #6 from manu at gcc dot gnu dot org  2007-01-20 16:52 -------
Not sure if the summary is 100% correct but it is far better than the previous
one.


-- 

manu at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
            Summary|Missing warning?            |Missing warning when trying
                   |                            |to explicitly construct a
                   |                            |virtual base


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


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

end of thread, other threads:[~2010-10-28  9:17 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <bug-21917-4@http.gcc.gnu.org/bugzilla/>
2010-10-28  9:17 ` [Bug c++/21917] Missing warning when trying to explicitly construct a virtual base redi at gcc dot gnu.org
     [not found] <bug-21917-6594@http.gcc.gnu.org/bugzilla/>
2007-01-20 16:52 ` manu at gcc dot gnu dot org
2008-06-05 23:07 ` r_q_einstein-gccgnuorg at yahoo 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).