https://gcc.gnu.org/bugzilla/show_bug.cgi?id=97755

            Bug ID: 97755
           Summary: Explicit default constructor is called during
                    copy-list-initialization with a warning only
           Product: gcc
           Version: 10.2.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: egor_suvorov at mail dot ru
  Target Milestone: ---

Consider the following test case:
https://gcc.gnu.org/git/?p=gcc.git;a=blob;f=gcc/testsuite/g%2B%2B.dg/cpp0x/initlist40.C

// PR c++/54835, DR 1518
// { dg-do compile { target c++11 } }
struct A
{
  explicit A(int = 42);
};
int main()
{
  A a1 = { };                   // { dg-error "explicit" }
  A a2 = { 24 };                // { dg-error "explicit" }
}

GCC fails to compile it, but the line with 'a1' emits only a warning:
"converting to 'A' from initializer list would use explicit constructor
'A::A(int)'". Hence, if I comment out the line with 'a2', compilation succeeds.

However, if I modify the test case slightly:

struct A
{
  explicit A();
  explicit A(int);
};
int main()
{
  A a1 = { };                   // { dg-error "explicit" }
  A a2 = { 24 };                // { dg-error "explicit" }
}

Both messages become errors.

I believe it's a regression between GCC 5 (correctly fails both test cases) and
GCC 6 (emits warning instead of error): https://godbolt.org/z/1o81h1

Looks like the change was brought by this commit:
https://gcc.gnu.org/git/?p=gcc.git&a=commit;h=e7838ec9d2ea06e844ef23660862781b81a26329
from this bug: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=54835

I'm suspicious that the code says "When converting from an init list we
consider explicit constructors, but actually trying to call one is an error.",
but then proceeds to call `pedwarn` instead of `error` in some cases.

Reply via email to