public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/97755] New: Explicit default constructor is called during copy-list-initialization with a warning only
@ 2020-11-08 16:26 egor_suvorov at mail dot ru
  2020-11-08 18:08 ` [Bug c++/97755] " harald at gigawatt dot nl
  0 siblings, 1 reply; 2+ messages in thread
From: egor_suvorov at mail dot ru @ 2020-11-08 16:26 UTC (permalink / raw)
  To: gcc-bugs

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.

^ permalink raw reply	[flat|nested] 2+ messages in thread

* [Bug c++/97755] Explicit default constructor is called during copy-list-initialization with a warning only
  2020-11-08 16:26 [Bug c++/97755] New: Explicit default constructor is called during copy-list-initialization with a warning only egor_suvorov at mail dot ru
@ 2020-11-08 18:08 ` harald at gigawatt dot nl
  0 siblings, 0 replies; 2+ messages in thread
From: harald at gigawatt dot nl @ 2020-11-08 18:08 UTC (permalink / raw)
  To: gcc-bugs

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

Harald van Dijk <harald at gigawatt dot nl> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |harald at gigawatt dot nl

--- Comment #1 from Harald van Dijk <harald at gigawatt dot nl> ---
This may be in order to ensure that the following valid C++03 code is accepted
in C++11 mode as well, to limit the impact when the default language version
was changed:

  struct A {
    explicit A(int = 24);
  };
  int main() {
    A a[1] = {};
  }

This did not get diagnosed in GCC 5 in any mode. GCC 6 accepts it without a
warning in C++03 mode, and accepts it with a warning in C++11 mode.

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2020-11-08 18:08 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-11-08 16:26 [Bug c++/97755] New: Explicit default constructor is called during copy-list-initialization with a warning only egor_suvorov at mail dot ru
2020-11-08 18:08 ` [Bug c++/97755] " harald at gigawatt dot nl

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