* [Bug c++/19249] abstract classes should not access virtually inherited class constructor
2005-01-04 5:36 [Bug c++/19249] New: " gianni at mariani dot ws
@ 2005-01-04 5:42 ` pinskia at gcc dot gnu dot org
2005-01-04 9:15 ` pinskia at gcc dot gnu dot org
` (6 subsequent siblings)
7 siblings, 0 replies; 12+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2005-01-04 5:42 UTC (permalink / raw)
To: gcc-bugs
------- Additional Comments From pinskia at gcc dot gnu dot org 2005-01-04 05:42 -------
Note the comeau C++ compiler also rejects the code:
"ComeauTest.c", line 9: error: "controller::controller()" is inaccessible
: virtual public controller
^
detected during implicit generation of "Interface::Interface()" at
line 22
1 error detected in the compilation of "ComeauTest.
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=19249
^ permalink raw reply [flat|nested] 12+ messages in thread
* [Bug c++/19249] abstract classes should not access virtually inherited class constructor
2005-01-04 5:36 [Bug c++/19249] New: " gianni at mariani dot ws
2005-01-04 5:42 ` [Bug c++/19249] " pinskia at gcc dot gnu dot org
@ 2005-01-04 9:15 ` pinskia at gcc dot gnu dot org
2005-01-05 14:30 ` jkanze at cheuvreux dot com
` (5 subsequent siblings)
7 siblings, 0 replies; 12+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2005-01-04 9:15 UTC (permalink / raw)
To: gcc-bugs
------- Additional Comments From pinskia at gcc dot gnu dot org 2005-01-04 09:14 -------
Bss, this is invalid and not because the standard only says he constructor is ignored.
12.6.2P6:
"If V does not have an accessible default constructor, the initialization is ill-formed. A mem-initializer
naming a a virtual bass class shall be ignored during execution of the constructor of any class that is
not the most derived class." So it says ignored, ignored does not mean not checking for accessible.
--
What |Removed |Added
----------------------------------------------------------------------------
Status|UNCONFIRMED |RESOLVED
Resolution| |INVALID
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=19249
^ permalink raw reply [flat|nested] 12+ messages in thread
* [Bug c++/19249] abstract classes should not access virtually inherited class constructor
2005-01-04 5:36 [Bug c++/19249] New: " gianni at mariani dot ws
2005-01-04 5:42 ` [Bug c++/19249] " pinskia at gcc dot gnu dot org
2005-01-04 9:15 ` pinskia at gcc dot gnu dot org
@ 2005-01-05 14:30 ` jkanze at cheuvreux dot com
2005-01-14 3:00 ` gianni at mariani dot ws
` (4 subsequent siblings)
7 siblings, 0 replies; 12+ messages in thread
From: jkanze at cheuvreux dot com @ 2005-01-05 14:30 UTC (permalink / raw)
To: gcc-bugs
------- Additional Comments From jkanze at cheuvreux dot com 2005-01-05 14:29 -------
The context of the quote from the standard is:
"If the constructor of the most derived class does not
specify a mem-initializer for the virtual base class
V ...". In the code submitted, the constructor of the
most derived class DOES specify a mem-initializer, so
none of what follows applies.
I think that there is a bit of history at play here.
All compilers I know reject the code, I suspect because
CFront rejected it, and nobody noticed that CFront was
in error here.
Note that the absence of a default initializer, when
it is required, is undefined behavior, so a trivial fix
would be to replace the call to the (non-existing)
constructor in the in-charge constructor with a call
to a function which displays an error message and calls
abort. A better fix would be to not generate the in-charge
constructor at all, resulting in a linker error if the class
was ever instantiated. (Not possible here, since the class is
abstract, but possible in the more general case.)
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=19249
^ permalink raw reply [flat|nested] 12+ messages in thread
* [Bug c++/19249] abstract classes should not access virtually inherited class constructor
2005-01-04 5:36 [Bug c++/19249] New: " gianni at mariani dot ws
` (2 preceding siblings ...)
2005-01-05 14:30 ` jkanze at cheuvreux dot com
@ 2005-01-14 3:00 ` gianni at mariani dot ws
2005-01-14 3:08 ` pinskia at gcc dot gnu dot org
` (3 subsequent siblings)
7 siblings, 0 replies; 12+ messages in thread
From: gianni at mariani dot ws @ 2005-01-14 3:00 UTC (permalink / raw)
To: gcc-bugs
------- Additional Comments From gianni at mariani dot ws 2005-01-14 03:00 -------
I request that we reopen this bug in light of some further discussions.
From: comp.lang.c++.moderated :
Sender: dtmoore@rijnh.nl
After reading your code and the discussion in the comp.std.c++ thread:
http://groups-beta.google.com/group/comp.std.c++/msg/3f6fda6a03cb5c6a
I guess I have to agree with James Kanze that the example code is
valid.
The relevant passage in the Standard (12.6.2/6) says:
" All subobjects representing virtual base classes are initialized by
the constructor of the most derived class (1.8). If the constructor of
the most derived class does not specify a mem-initializer for a virtual
base class V, then V's default constructor is called to initialize
the virtual base class subobject. If V does not have an accessible
default constructor, the initialization is ill-formed. A
mem-initializer naming a virtual base class shall be ignored during
execution of the constructor of any class that is not the most derived
class. " (Example omitted)
Since an abstract class can *never* be the most derived type, then it
is clear that all mem-initializers for virtual base classes of abstract
classes simply do not matter, since they will always be ignored.
However, since this point was not explicitly laid out in the standard,
I guess it is forgivable for compiler developers to have overlooked it
until now. Perhaps it would be a good idea for the next version of the
standard to explicitly make a provision for this case? I also think
the OP should resubmit the bug to gcc, including the rationales
from these NG discussions.
One last point, I do not agree (as suggested by James Kanze) that the
code would be valid if Interface were not an abstract class. It seems
to me that, according to the current Standard, the compiler must allow
for the possibility that an Interface object will be created somewhere
down the line, and make sure it has the proper initializers for its
base classes, virtual or not.
As a side note, can someone come up with an example where it is
impossible (or at least unreasonably difficult) for the designer of a
concrete class to provide valid, albeit potentially irrelevant,
initializers for its virtual base classes? I could not, but that
certainly doesn't mean it can't be done. For example, in the OP's
example, everything would be fine if the code were modified as follows:
(leading backquotes added to preserve indenting .. blame Google for
eating whitespace)
class Interface : public virtual Controller {
public: // or protected
` Interface() : Controller(0) {} // ALERT!! initializer will be
` // ignored in derived classes
` // rest of class
};
Ok, I can see why this might be considered "ugly", and it certainly
should be unnecessary for abstract classes, as I stated above. However
is there a reason why it shouldn't be required for concrete classes, as
currently mandated by the Standard?
Dave Moore
--
What |Removed |Added
----------------------------------------------------------------------------
Status|RESOLVED |UNCONFIRMED
Resolution|INVALID |
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=19249
^ permalink raw reply [flat|nested] 12+ messages in thread
* [Bug c++/19249] abstract classes should not access virtually inherited class constructor
2005-01-04 5:36 [Bug c++/19249] New: " gianni at mariani dot ws
` (3 preceding siblings ...)
2005-01-14 3:00 ` gianni at mariani dot ws
@ 2005-01-14 3:08 ` pinskia at gcc dot gnu dot org
2005-01-14 6:47 ` gianni at mariani dot ws
` (2 subsequent siblings)
7 siblings, 0 replies; 12+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2005-01-14 3:08 UTC (permalink / raw)
To: gcc-bugs
------- Additional Comments From pinskia at gcc dot gnu dot org 2005-01-14 03:08 -------
Quoting the standard again (the same passage which we all quoted):
"A mem-initializer naming a virtual base class shall be ignored during
execution of the constructor of any class that is not the most derived
class."
A mem-initializer is always implicated for base cases even if not named explicitly.
So this is still invalid code in my mind.
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=19249
^ permalink raw reply [flat|nested] 12+ messages in thread
* [Bug c++/19249] abstract classes should not access virtually inherited class constructor
2005-01-04 5:36 [Bug c++/19249] New: " gianni at mariani dot ws
` (4 preceding siblings ...)
2005-01-14 3:08 ` pinskia at gcc dot gnu dot org
@ 2005-01-14 6:47 ` gianni at mariani dot ws
2005-05-01 2:51 ` pinskia at gcc dot gnu dot org
2005-07-23 20:07 ` bangerth at dealii dot org
7 siblings, 0 replies; 12+ messages in thread
From: gianni at mariani dot ws @ 2005-01-14 6:47 UTC (permalink / raw)
To: gcc-bugs
------- Additional Comments From gianni at mariani dot ws 2005-01-14 06:47 -------
> Quoting the standard again (the same passage which we all quoted):
James Kanze added a comment in this bug - I'll quote it here:
> The context of the quote from the standard is:
> "If the constructor of the most derived class does not
> specify a mem-initializer for the virtual base class
> V ...". In the code submitted, the constructor of the
> most derived class DOES specify a mem-initializer, so
> none of what follows applies.
Comments ?
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=19249
^ permalink raw reply [flat|nested] 12+ messages in thread
* [Bug c++/19249] abstract classes should not access virtually inherited class constructor
2005-01-04 5:36 [Bug c++/19249] New: " gianni at mariani dot ws
` (5 preceding siblings ...)
2005-01-14 6:47 ` gianni at mariani dot ws
@ 2005-05-01 2:51 ` pinskia at gcc dot gnu dot org
2005-07-23 20:07 ` bangerth at dealii dot org
7 siblings, 0 replies; 12+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2005-05-01 2:51 UTC (permalink / raw)
To: gcc-bugs
--
What |Removed |Added
----------------------------------------------------------------------------
Keywords| |rejects-valid
Known to fail| |3.3.4 3.4.0 3.4.1 3.4.2
| |3.4.3 4.0.0 2.95.3
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=19249
^ permalink raw reply [flat|nested] 12+ messages in thread
* [Bug c++/19249] abstract classes should not access virtually inherited class constructor
2005-01-04 5:36 [Bug c++/19249] New: " gianni at mariani dot ws
` (6 preceding siblings ...)
2005-05-01 2:51 ` pinskia at gcc dot gnu dot org
@ 2005-07-23 20:07 ` bangerth at dealii dot org
7 siblings, 0 replies; 12+ messages in thread
From: bangerth at dealii dot org @ 2005-07-23 20:07 UTC (permalink / raw)
To: gcc-bugs
------- Additional Comments From bangerth at dealii dot org 2005-07-23 20:04 -------
I think we should accept this as an enhancement request.
W.
--
What |Removed |Added
----------------------------------------------------------------------------
Severity|normal |enhancement
Status|UNCONFIRMED |NEW
Ever Confirmed| |1
Keywords|rejects-valid |
Last reconfirmed|0000-00-00 00:00:00 |2005-07-23 20:04:22
date| |
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=19249
^ permalink raw reply [flat|nested] 12+ messages in thread