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; 4+ 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] 4+ messages in thread

end of thread, other threads:[~2009-08-25 15:26 UTC | newest]

Thread overview: 4+ 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

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).