From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 2CCF63858C54; Tue, 27 Feb 2024 03:56:38 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 2CCF63858C54 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1709006198; bh=31AsLiP01XXYqwZEM6zF8vZKPUtUyI3CUo1k98ALEeo=; h=From:To:Subject:Date:From; b=EuZ6S689SPNjhIeEfWlZStkgcvNBjbDcJjPSfJcmgZXWGtFawQqWj+NcDpDu70xT2 3tjqdmZqLW/sFAsNY7jlE1BywfoZW+FD4QzbsK+g+4lyMriRumqTH6fRmIo2IVcbfk cZWlHdqFYBskfKSf4kc9JBP/6xmPgKhHC20D/B88= From: "yx_liu at hotmail dot com" To: gcc-bugs@gcc.gnu.org Subject: [Bug c++/114123] New: list-initialization with a single element Date: Tue, 27 Feb 2024 03:56:37 +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: 13.2.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: yx_liu at hotmail dot com 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 List-Id: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D114123 Bug ID: 114123 Summary: list-initialization with a single element Product: gcc Version: 13.2.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: yx_liu at hotmail dot com Target Milestone: --- https://godbolt.org/z/fPd4q7zMd The issue happens with gcc 13.2 and trunk. The following is the code: ``` #include #include using namespace std; struct A { int x; A(int x_) : x(x_) {printf("%p : A(int %d)\n", this, x);} A(const A& a) { x =3D a.x; printf("%p : A(const A& %p)\n", this, &a);} A(const vector& a) { printf ("%p : vector& %p\n", this, &a);} }; int main() { vector a{1,2}; vector b{a}; printf("%ld\n", b.size()); } ``` Based on my understanding of https://cplusplus.github.io/CWG/issues/1467.ht= ml, If T is a class type and the initializer list has a single element of type = cv U, where U is T or a class derived from T, the object is initialized from t= hat element (by copy-initialization for copy-list-initialization, or by direct-initialization for direct-list-initialization). b should be direct-initialized by a, i.e. equivalent to=20 vector b(a); I would expect the copy ctor of vector to be called, and the elements of= a will be copied to b, and b.size() will be 2. However, A(const vector& a) is called to contruct b and b.size() is 1. Currently clang trunk has the expected behavior and b.size() is 1. https://godbolt.org/z/dh7d5x81T A few days ago when clang tried to implement CWG2137 ( https://github.com/llvm/llvm-project/pull/77768). It showed the same behavi= or as gcc. However that PR was reverted and clang went back to the expected behavior.=