public inbox for gcc-bugs@sourceware.org help / color / mirror / Atom feed
From: "kretz at kde dot org" <gcc-bugzilla@gcc.gnu.org> To: gcc-bugs@gcc.gnu.org Subject: [Bug c++/40685] New: explicit constructor is used where only implicit ctors are allowed Date: Wed, 08 Jul 2009 16:03:00 -0000 [thread overview] Message-ID: <bug-40685-17603@http.gcc.gnu.org/bugzilla/> (raw) 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
next reply other threads:[~2009-07-08 16:03 UTC|newest] Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top 2009-07-08 16:03 kretz at kde dot org [this message] 2009-07-29 14:51 ` [Bug c++/40685] " kretz at kde dot org 2009-08-25 14:39 ` bangerth at gmail dot com 2009-08-25 15:26 ` kretz at kde dot org
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=bug-40685-17603@http.gcc.gnu.org/bugzilla/ \ --to=gcc-bugzilla@gcc.gnu.org \ --cc=gcc-bugs@gcc.gnu.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
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).