From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id BE54A3858D29; Sun, 21 Mar 2021 12:16:02 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org BE54A3858D29 From: "redi at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug c++/61961] Add new warning when initializer-list constructor chosen for uniform init that doesn't intend to use initializer_list Date: Sun, 21 Mar 2021 12:16:02 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: c++ X-Bugzilla-Version: 5.0 X-Bugzilla-Keywords: diagnostic X-Bugzilla-Severity: enhancement X-Bugzilla-Who: redi at gcc dot gnu.org X-Bugzilla-Status: NEW 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: Message-ID: In-Reply-To: References: 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, 21 Mar 2021 12:16:02 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D61961 --- Comment #3 from Jonathan Wakely --- (In reply to Jonathan Wakely from comment #0) > The semantics I suggest are to warn when: >=20 > * an initializer-list constructor is selected by overload resolution > * the elements of the braced-init-list are not all the same type > * another (non-initializer-list) constructor is viable This would also be useful to warn for the CWG 2137 / PR 76262 / PR 85577 ca= ses where an initializer-list constructor is chosen for a braced-init-list with= a single element of the same type as the class being constructed. Users almost always want A{a} to use a copy constructor, and are surprised when GCC choo= ses an initializer-list constructor (which other compilers don't do). So revised suggestion for the semantics: * an initializer-list constructor is selected by overload resolution * another (non-initializer-list) constructor is viable * either the braced-init-list has more than one element and they are not all the same type, or it has exactly one element and its type is the same as the class being constructed. I think this should be included in -Wall. If the initializer-list construct= or is really intended then the warning can be suppressed by explicitly convert= ing the initializers to the intended type, which more clearly expresses the intended meaning of the code anyway.=