bogus error on constructor call with gcc 2.95.2

E. Jay Berkenbilt
Sun Oct 15 20:12:00 GMT 2000

With gcc 2.95.2, on this C++ file:

class A
    A(int, int);

class B
    B(A const&);

void f()
    B(A(0, 1));

you get this output:

--------------------------------------------------------------------------- In function `void f()': no matching function for call to `B::B (int, int)' candidates are: B::B(const A &)                 B::B(const B &)


 * I believe that my code above is valid.  An expression is a valid
   statement in C++, and B(A(0, 1)) is certainly a valid expression:
   it creates a temporary B initialized by a temporary A.  The above
   code should simply call the A constructor, the B constructor, the B
   destructor, and the A destructor since the objects are not bound to

 * Even if someone maintains that the above code is not valid, the
   error message seems wrong.  It is certainly the case that B is
   being called with an A as an argument, not with A's arguments.  I
   have not tried declaring an (int, int) constructor to B, defining
   all these, linking, and seeing which constructor is called.

 * The following code fragments compile without error:

   B b(A(0, 1));

   A a(0, 1);

 * I've used this type of construct before including in older versions
   of gcc.  It may look odd at first, but it can be useful to test
   whether creation of an object will succeed.  Mainly I use
   constructs like this in test suites to ensure that constructing an
   object with invalid arguments will raise a suitable exception....

 * This problem also exists in the fictitious 2.96 release included in
   RedHat Linux 7.0.  However, I tested the above in 2.95.2 before
   reporting the bug.  I have not tested it in a current developer

E. Jay Berkenbilt (  |

More information about the Gcc-bugs mailing list