From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id C0CEB3854833; Sun, 8 Nov 2020 16:26:38 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org C0CEB3854833 From: "egor_suvorov at mail dot ru" To: gcc-bugs@gcc.gnu.org Subject: [Bug c++/97755] New: Explicit default constructor is called during copy-list-initialization with a warning only Date: Sun, 08 Nov 2020 16:26:38 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: c++ X-Bugzilla-Version: 10.2.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: egor_suvorov at mail dot ru X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Resolution: X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: bug_id short_desc product version bug_status bug_severity priority component assigned_to reporter target_milestone Message-ID: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 X-BeenThere: gcc-bugs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-bugs mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 08 Nov 2020 16:26:38 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D97755 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=3Dgcc.git;a=3Dblob;f=3Dgcc/testsuite/g%2B%2B.dg/= cpp0x/initlist40.C // PR c++/54835, DR 1518 // { dg-do compile { target c++11 } } struct A { explicit A(int =3D 42); }; int main() { A a1 =3D { }; // { dg-error "explicit" } A a2 =3D { 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 succe= eds. However, if I modify the test case slightly: struct A { explicit A(); explicit A(int); }; int main() { A a1 =3D { }; // { dg-error "explicit" } A a2 =3D { 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=3Dgcc.git&a=3Dcommit;h=3De7838ec9d2ea06e844ef236= 60862781b81a26329 from this bug: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D54835 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.=