public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/20207] New: null constructor not needed in multiple inheritance
@ 2005-02-25 19:00 Serge dot Iovleff at univ-lille1 dot fr
2005-02-25 21:11 ` [Bug c++/20207] " pinskia at gcc dot gnu dot org
` (3 more replies)
0 siblings, 4 replies; 6+ messages in thread
From: Serge dot Iovleff at univ-lille1 dot fr @ 2005-02-25 19:00 UTC (permalink / raw)
To: gcc-bugs
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain, Size: 2506 bytes --]
In a "dreaded" diamon hierarchy
A0
|
A
/ \
B C
\ /
D
I get a request for a default constructor for A0 from the compiler
(gcc 3.4.4 )
If I drop A0, the error desappear.
testtemplate2.cpp: In constructor `B<TYPE>::B(int) [with TYPE = int]':
testtemplate2.cpp:57: instantiated from `D<TYPE>::D(int) [with TYPE =
int]'<int>::A0() »
testtemplate2.cpp:64: instantiated from here<int>::A0(const A0<int>&)
testtemplate2.cpp:37: erreur: pas de fonction concordante pour l'appel à «
A0<int>::A0() »
testtemplate2.cpp:15: note: candidats sont: A0<int>::A0(const A0<int>&)
testtemplate2.cpp:18: note: A0<TYPE>::A0(TYPE) [with TYPE = int]
testtemplate2.cpp: In constructor `C<TYPE>::C(int) [with TYPE = int]':
testtemplate2.cpp:57: instantiated from `D<TYPE>::D(int) [with TYPE = int]'
testtemplate2.cpp:64: instantiated from here
testtemplate2.cpp:47: erreur: pas de fonction concordante pour l'appel à «
A0<int>::A0() »
testtemplate2.cpp:15: note: candidats sont: A0<int>::A0(const A0<int>&)
testtemplate2.cpp:18: note: A0<TYPE>::A0(TYPE) [with TYPE = int]
template<class TYPE>
class A0
{ protected:
const int n;
public:
A0(TYPE a ) : n(a) { ;}
~A0() { ;}
virtual void foo() =0;
};
template<class TYPE>
class A : public virtual A0<TYPE>
{
public:
A(TYPE a ) : A0<TYPE>(a) { ;}
~A() { ;}
virtual void foo() =0;
};
template<class TYPE>
class B : public virtual A<TYPE>
{
public:
B(int b= 0) : A<TYPE>(b)
{ ;}
~B() { ;}
virtual void foo() =0;
};
template<class TYPE>
class C : public virtual A<TYPE>
{
public:
C(int c= 0) : A<TYPE>(c)
{ ;}
~C() { ;}
virtual void foo() =0;
};
template<class TYPE>
class D : public virtual B<TYPE>, public virtual C<TYPE>
{
public:
D(int d= 0) : A0<TYPE>(d), A<TYPE>(d), B<TYPE>(d), C<TYPE>(d)
{ ;}
~D() { ;}
virtual void foo() { ;}
};
int main(int argc, char *argv[])
{
D<int> d(4);
}
--
Summary: null constructor not needed in multiple inheritance
Product: gcc
Version: 3.4.4
Status: UNCONFIRMED
Severity: normal
Priority: P2
Component: c++
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: Serge dot Iovleff at univ-lille1 dot fr
CC: gcc-bugs at gcc dot gnu dot org
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=20207
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug c++/20207] null constructor not needed in multiple inheritance
2005-02-25 19:00 [Bug c++/20207] New: null constructor not needed in multiple inheritance Serge dot Iovleff at univ-lille1 dot fr
@ 2005-02-25 21:11 ` pinskia at gcc dot gnu dot org
2005-02-25 21:29 ` Serge dot Iovleff at univ-lille1 dot fr
` (2 subsequent siblings)
3 siblings, 0 replies; 6+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2005-02-25 21:11 UTC (permalink / raw)
To: gcc-bugs
------- Additional Comments From pinskia at gcc dot gnu dot org 2005-02-25 15:10 -------
I think this is invalid code but I don't know how to produce it right now.
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=20207
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug c++/20207] null constructor not needed in multiple inheritance
2005-02-25 19:00 [Bug c++/20207] New: null constructor not needed in multiple inheritance Serge dot Iovleff at univ-lille1 dot fr
2005-02-25 21:11 ` [Bug c++/20207] " pinskia at gcc dot gnu dot org
@ 2005-02-25 21:29 ` Serge dot Iovleff at univ-lille1 dot fr
2005-03-01 5:38 ` sstrasser at systemhaus-gruppe dot de
2005-03-01 11:16 ` Serge dot Iovleff at univ-lille1 dot fr
3 siblings, 0 replies; 6+ messages in thread
From: Serge dot Iovleff at univ-lille1 dot fr @ 2005-02-25 21:29 UTC (permalink / raw)
To: gcc-bugs
------- Additional Comments From Serge dot Iovleff at univ-lille1 dot fr 2005-02-25 15:43 -------
(In reply to comment #1)
> I think this is invalid code but I don't know how to produce it right now.
Yes you can add an explicit call to the constructor of A0 in B and C,
in this case the error deseappear.
hovewer, as B and C are abstract virtual class, this constructor should never be
called by these class, but only by the derived class, like D.
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=20207
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug c++/20207] null constructor not needed in multiple inheritance
2005-02-25 19:00 [Bug c++/20207] New: null constructor not needed in multiple inheritance Serge dot Iovleff at univ-lille1 dot fr
2005-02-25 21:11 ` [Bug c++/20207] " pinskia at gcc dot gnu dot org
2005-02-25 21:29 ` Serge dot Iovleff at univ-lille1 dot fr
@ 2005-03-01 5:38 ` sstrasser at systemhaus-gruppe dot de
2005-03-01 11:16 ` Serge dot Iovleff at univ-lille1 dot fr
3 siblings, 0 replies; 6+ messages in thread
From: sstrasser at systemhaus-gruppe dot de @ 2005-03-01 5:38 UTC (permalink / raw)
To: gcc-bugs
------- Additional Comments From sstrasser at systemhaus-gruppe dot de 2005-03-01 05:38 -------
it is invalid to use A0 in the base constructor list of D, because A0 is not a
virtual base for D. .it doesn't matter that the inheritance A->A0 is declared
virtual, 2 trees which both inherit A0 must join at D to use it in base
constructor list)
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=20207
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug c++/20207] null constructor not needed in multiple inheritance
2005-02-25 19:00 [Bug c++/20207] New: null constructor not needed in multiple inheritance Serge dot Iovleff at univ-lille1 dot fr
` (2 preceding siblings ...)
2005-03-01 5:38 ` sstrasser at systemhaus-gruppe dot de
@ 2005-03-01 11:16 ` Serge dot Iovleff at univ-lille1 dot fr
3 siblings, 0 replies; 6+ messages in thread
From: Serge dot Iovleff at univ-lille1 dot fr @ 2005-03-01 11:16 UTC (permalink / raw)
To: gcc-bugs
------- Additional Comments From Serge dot Iovleff at univ-lille1 dot fr 2005-03-01 11:16 -------
(In reply to comment #3)
> it is invalid to use A0 in the base constructor list of D, because A0 is not a
> virtual base for D. .it doesn't matter that the inheritance A->A0 is declared
> virtual, 2 trees which both inherit A0 must join at D to use it in base
> constructor list)
No, I think it is invalid to use A0 in the base constructor list of B and C,
even if g++ allow it...
And I think also A0 is a virtual base for D, as it would appear twice (D inherit
from B and C)
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=20207
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug c++/20207] null constructor not needed in multiple inheritance
[not found] <bug-20207-9401@http.gcc.gnu.org/bugzilla/>
@ 2005-11-29 20:33 ` reichelt at gcc dot gnu dot org
0 siblings, 0 replies; 6+ messages in thread
From: reichelt at gcc dot gnu dot org @ 2005-11-29 20:33 UTC (permalink / raw)
To: gcc-bugs
------- Comment #5 from reichelt at gcc dot gnu dot org 2005-11-29 20:33 -------
This is not a bug in GCC. The code is invalid.
Let's consider the following simplified example which is just a
part of the diamond:
A0
|
A
/
B
==========================
struct A0
{
A0(int);
};
struct A : virtual A0
{
A() : A0(0) {}
};
struct B : virtual A
{
B() : A() {}
};
==========================
[12.6.2]/6 of the standard states:
All sub-objects representing virtual base classes are initialized
by the constructor of the most derived class. 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.
The first sentence means that A *and* A0 are initialized by the
constructor of B. The second sentence says that V (which is A0 in
our case) is default constructed since B's constructor does not
specify a mem-initializer for V==A0. The next sentence says that
the example is ill-formed since V==A0 does not have an accessible
default constructor. That's why g++ gives the following diagnostic:
bug.cc: In constructor 'B::B()':
bug.cc:13: error: no matching function for call to 'A0::A0()'
bug.cc:3: note: candidates are: A0::A0(int)
bug.cc:2: note: A0::A0(const A0&)
The last sentence says that A0(0) is ignored in the constructor
of A when called by B (which makes sense, since A0 should be
constructed directly by B's constructor).
--
reichelt at gcc dot gnu dot org changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |reichelt at gcc dot gnu dot
| |org
Status|UNCONFIRMED |RESOLVED
Resolution| |INVALID
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=20207
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2005-11-29 20:33 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-02-25 19:00 [Bug c++/20207] New: null constructor not needed in multiple inheritance Serge dot Iovleff at univ-lille1 dot fr
2005-02-25 21:11 ` [Bug c++/20207] " pinskia at gcc dot gnu dot org
2005-02-25 21:29 ` Serge dot Iovleff at univ-lille1 dot fr
2005-03-01 5:38 ` sstrasser at systemhaus-gruppe dot de
2005-03-01 11:16 ` Serge dot Iovleff at univ-lille1 dot fr
[not found] <bug-20207-9401@http.gcc.gnu.org/bugzilla/>
2005-11-29 20:33 ` reichelt at gcc dot gnu 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).