This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c++/40685] New: explicit constructor is used where only implicit ctors are allowed
- From: "kretz at kde dot org" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: 8 Jul 2009 16:02:57 -0000
- Subject: [Bug c++/40685] New: explicit constructor is used where only implicit ctors are allowed
- Reply-to: gcc-bugzilla at gcc dot gnu dot org
The following testcase fails on g++ 4.4.0 and 4.3.2:
#include <cstdlib>
enum Enum {
Foo
};
class A
{
public:
A(int y) : x(y) {}
explicit A(Enum) : x(1) {}
int x;
};
static void fun(A a = Foo)
{
if (a.x != static_cast<int>(Foo)) {
abort();
}
}
int main()
{
fun();
return 0;
}
If the A(int) ctor is removed the program does not compile, as is expected. If
the line "A a = Foo" appears inside the function instead of the parameter list
then g++ correctly uses the A(int) ctor.
While on that topic: The code above was meant to use the Enum ctor, it would be
nice if g++ emits a warning about the emitted code probably using the wrong
ctor.
--
Summary: explicit constructor is used where only implicit ctors
are allowed
Product: gcc
Version: 4.4.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: kretz at kde dot org
GCC build triplet: x86_64-unknown-linux-gnu
GCC host triplet: x86_64-unknown-linux-gnu
GCC target triplet: x86_64-unknown-linux-gnu
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=40685