g++-2.95.2 explicit constructor
Ulf Larsson
ulf@sm.luth.se
Tue Jan 25 22:41:00 GMT 2000
Mike Stump wrote:
> > Date: Tue, 25 Jan 2000 11:22:43 +0100
> > From: Ulf Larsson <ulf@sm.luth.se>
> > To: gcc-bugs@gcc.gnu.org
>
> > struct A
> > {
> > explicit A(int);
> > };
>
> > struct B
> > {
> > B(A const &);
> > };
>
> > struct C
> > {
> > C(B const &);
> > };
>
> > void
> > f()
> > {
> > C c(B(A(1)));
> > }
>
> Are you missing B (A a) or A (A)? I'm wondering if this isn't a bug.
What makes me believe it is a bug is that g++-2.95.2 accept the code if
the explicit keyword is removed. And older version of the compiler such
as egcs-1.1.2 accept the code.
If g++-2.95.2 is correct then I find the error report a bit
confusing,"no matching function for call to `B::B (int)'". To me it
looks like g++ treat
C c(B(A(1)));
as
C c(B(1));
With explicit A::A(int) there is then no way to construct B from int.
The same problem appears if explicit A(int) is replaced by A(int,int)
and C c(B(A(1))) with C c(B(A(1,1)))
Ulf
More information about the Gcc-bugs
mailing list