public inbox for gcc-bugs@sourceware.org help / color / mirror / Atom feed
* [Bug c++/40685] New: explicit constructor is used where only implicit ctors are allowed @ 2009-07-08 16:03 kretz at kde dot org 2009-07-29 14:51 ` [Bug c++/40685] " kretz at kde dot org ` (2 more replies) 0 siblings, 3 replies; 6+ messages in thread From: kretz at kde dot org @ 2009-07-08 16:03 UTC (permalink / raw) To: gcc-bugs 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 ^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug c++/40685] explicit constructor is used where only implicit ctors are allowed 2009-07-08 16:03 [Bug c++/40685] New: explicit constructor is used where only implicit ctors are allowed kretz at kde dot org @ 2009-07-29 14:51 ` 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 2 siblings, 0 replies; 6+ messages in thread From: kretz at kde dot org @ 2009-07-29 14:51 UTC (permalink / raw) To: gcc-bugs ------- Comment #1 from kretz at kde dot org 2009-07-29 14:51 ------- I just tested with 4.4.1 and I can still confirm the problem. -- kretz at kde dot org changed: What |Removed |Added ---------------------------------------------------------------------------- Known to fail| |4.4.0 4.4.1 4.3.2 4.3.3 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=40685 ^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug c++/40685] explicit constructor is used where only implicit ctors are allowed 2009-07-08 16:03 [Bug c++/40685] New: explicit constructor is used where only implicit ctors are allowed kretz at kde dot org 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 2 siblings, 0 replies; 6+ messages in thread From: bangerth at gmail dot com @ 2009-08-25 14:39 UTC (permalink / raw) To: gcc-bugs ------- Comment #2 from bangerth at gmail dot com 2009-08-25 14:39 ------- Hm, confusing: ----------------------------- enum E {e}; struct A { A(int); explicit A(E) {}; }; int main () { A a = e; } ----------------------------- This compiles but not links becase A::A(int) is called. If I remove the explicit keyword, it calls A::A(E) and links fine. I must admit that I don't know whether that's correct. icc concurs with gcc, by the way. W. -- bangerth at gmail dot com changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |bangerth at gmail dot com http://gcc.gnu.org/bugzilla/show_bug.cgi?id=40685 ^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug c++/40685] explicit constructor is used where only implicit ctors are allowed 2009-07-08 16:03 [Bug c++/40685] New: explicit constructor is used where only implicit ctors are allowed kretz at kde dot org 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 2 siblings, 0 replies; 6+ messages in thread From: kretz at kde dot org @ 2009-08-25 15:26 UTC (permalink / raw) To: gcc-bugs ------- Comment #3 from kretz at kde dot org 2009-08-25 15:26 ------- Actually I came across this problem because my code was failing on MSVC and icc. Then I noticed that icc compiles the code, the one that I pasted, differently. On further investigation I decided that gcc is at fault and that my code was wrong (which I didn't notice because gcc made my wrong right again :-) ). I tested with icc 11.1 and MSVC 2008. For the testcase you describe I thought gcc works correctly. I could only reproduce the problem if the ctor is called as a default argument of a function. -- http://gcc.gnu.org/bugzilla/show_bug.cgi?id=40685 ^ permalink raw reply [flat|nested] 6+ messages in thread
[parent not found: <bug-40685-4@http.gcc.gnu.org/bugzilla/>]
* [Bug c++/40685] explicit constructor is used where only implicit ctors are allowed [not found] <bug-40685-4@http.gcc.gnu.org/bugzilla/> @ 2011-08-18 15:39 ` redi at gcc dot gnu.org 2011-08-18 16:45 ` paolo.carlini at oracle dot com 1 sibling, 0 replies; 6+ messages in thread From: redi at gcc dot gnu.org @ 2011-08-18 15:39 UTC (permalink / raw) To: gcc-bugs http://gcc.gnu.org/bugzilla/show_bug.cgi?id=40685 Jonathan Wakely <redi at gcc dot gnu.org> changed: What |Removed |Added ---------------------------------------------------------------------------- Known to work| |4.7.0 Known to fail| |4.5.2, 4.6.1 --- Comment #4 from Jonathan Wakely <redi at gcc dot gnu.org> 2011-08-18 15:31:23 UTC --- 4.6 incorrectly gives an error: e.cc:25:9: error: converting to 'A' from initializer list would use explicit constructor 'A::A(Enum)' and 4.7 compiles it correctly, so I think this is now fixed ^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug c++/40685] explicit constructor is used where only implicit ctors are allowed [not found] <bug-40685-4@http.gcc.gnu.org/bugzilla/> 2011-08-18 15:39 ` redi at gcc dot gnu.org @ 2011-08-18 16:45 ` paolo.carlini at oracle dot com 1 sibling, 0 replies; 6+ messages in thread From: paolo.carlini at oracle dot com @ 2011-08-18 16:45 UTC (permalink / raw) To: gcc-bugs http://gcc.gnu.org/bugzilla/show_bug.cgi?id=40685 Paolo Carlini <paolo.carlini at oracle dot com> changed: What |Removed |Added ---------------------------------------------------------------------------- Status|UNCONFIRMED |RESOLVED Resolution| |FIXED Target Milestone|--- |4.7.0 --- Comment #5 from Paolo Carlini <paolo.carlini at oracle dot com> 2011-08-18 16:44:41 UTC --- Let's close this then. ^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2011-08-18 16:45 UTC | newest] Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2009-07-08 16:03 [Bug c++/40685] New: explicit constructor is used where only implicit ctors are allowed kretz at kde dot org 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 [not found] <bug-40685-4@http.gcc.gnu.org/bugzilla/> 2011-08-18 15:39 ` redi at gcc dot gnu.org 2011-08-18 16:45 ` paolo.carlini at oracle dot com
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).