public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/19249] abstract classes should not access virtually inherited class constructor
       [not found] <bug-19249-4@http.gcc.gnu.org/bugzilla/>
@ 2021-12-08  7:56 ` pinskia at gcc dot gnu.org
  2021-12-08  8:03 ` pinskia at gcc dot gnu.org
  1 sibling, 0 replies; 12+ messages in thread
From: pinskia at gcc dot gnu.org @ 2021-12-08  7:56 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=19249

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
      Known to fail|                            |

--- Comment #10 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
GCC 7+ with -std=c++14 (and above) accept the code.

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

* [Bug c++/19249] abstract classes should not access virtually inherited class constructor
       [not found] <bug-19249-4@http.gcc.gnu.org/bugzilla/>
  2021-12-08  7:56 ` [Bug c++/19249] abstract classes should not access virtually inherited class constructor pinskia at gcc dot gnu.org
@ 2021-12-08  8:03 ` pinskia at gcc dot gnu.org
  1 sibling, 0 replies; 12+ messages in thread
From: pinskia at gcc dot gnu.org @ 2021-12-08  8:03 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=19249

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           See Also|                            |https://gcc.gnu.org/bugzill
                   |                            |a/show_bug.cgi?id=79393
         Resolution|---                         |FIXED
   Target Milestone|---                         |7.0
             Status|NEW                         |RESOLVED

--- Comment #11 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Fixed for GCC 7+.
See the discussion in PR 79393 on everything.

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

* [Bug c++/19249] abstract classes should not access virtually inherited class constructor
       [not found] <bug-19249-2828@http.gcc.gnu.org/bugzilla/>
  2006-11-04 15:34 ` jens dot maurer at gmx dot net
@ 2006-11-04 15:44 ` jens dot maurer at gmx dot net
  1 sibling, 0 replies; 12+ messages in thread
From: jens dot maurer at gmx dot net @ 2006-11-04 15:44 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #9 from jens dot maurer at gmx dot net  2006-11-04 15:44 -------
I would like to point out that C++ std ore issue 257 "Abstract base
constructors and virtual base initialization" (see
http://www.open-std.org/jtc1/sc22/wg21/docs/cwg_active.html#257) deals with
this very issue.  I have submitted a proposed resolution that (hopefully)
unambiguously describes what James Kanze advocates.


-- 


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
       [not found] <bug-19249-2828@http.gcc.gnu.org/bugzilla/>
@ 2006-11-04 15:34 ` jens dot maurer at gmx dot net
  2006-11-04 15:44 ` jens dot maurer at gmx dot net
  1 sibling, 0 replies; 12+ messages in thread
From: jens dot maurer at gmx dot net @ 2006-11-04 15:34 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #8 from jens dot maurer at gmx dot net  2006-11-04 15:34 -------
*** Bug 29706 has been marked as a duplicate of this bug. ***


-- 

jens dot maurer at gmx dot net changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |jens dot maurer at gmx dot
                   |                            |net


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

* [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
                   ` (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
                   ` (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
                   ` (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
  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
  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 ` 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

end of thread, other threads:[~2021-12-08  8:03 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <bug-19249-4@http.gcc.gnu.org/bugzilla/>
2021-12-08  7:56 ` [Bug c++/19249] abstract classes should not access virtually inherited class constructor pinskia at gcc dot gnu.org
2021-12-08  8:03 ` pinskia at gcc dot gnu.org
     [not found] <bug-19249-2828@http.gcc.gnu.org/bugzilla/>
2006-11-04 15:34 ` jens dot maurer at gmx dot net
2006-11-04 15:44 ` jens dot maurer at gmx dot net
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
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

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