From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 5A4A73858D38; Mon, 12 Feb 2024 05:59:32 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 5A4A73858D38 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1707717572; bh=/vZkr8aYCc9RiIYmNGbqYJiWumPrZxCZQM+8qBodFmc=; h=From:To:Subject:Date:In-Reply-To:References:From; b=jD9hWzDzo3Ah89b0ISUAJpAz8gzriwvk21TZq1qdT3reaIZ2ZB8Ld4MgCKpXeBzMn Pdj5msNlGzKwbwvMXuteTT3HTn+cFkKGy8fPpDeqHkqTJPp/ggQrQSwBI7DDEaiqIy sBFRRYDAXddunbnuZMDz+zcT7HhvIst019ZzR6rc= From: "pinskia at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug c++/113884] GCC rejects valid program saying ambiguous call when using std::vector Date: Mon, 12 Feb 2024 05:59:32 +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: unknown X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: pinskia at gcc dot gnu.org X-Bugzilla-Status: RESOLVED X-Bugzilla-Resolution: DUPLICATE 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 List-Id: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D113884 --- Comment #8 from Andrew Pinski --- (In reply to Jason Liam from comment #7) > (In reply to Andrew Pinski from comment #5) > > std::vector 's constructor which takes std::size_t is marked as explici= t. >=20 > But you're missing that the initializer list ctor is preferred/choosen ov= er > the size_t arg ctor.=20 That is different from your original example. This is closer to your original example: ``` #include struct B { B(std::initializer_list); }; struct C { explicit C(int); }; void func(B); void func(C); int main() { func({ 4.2 }); } ``` here we have two calls to func, one which takes B and the other which takes= C. In the case case of copy-list-initialization, it is ambigous which is to be constructed as copy-list-initialization for overload resolution; explicit constructors are looked at but only an error if it was chosen. Note narrowi= ng is not taken into account for overload resolution too; maybe that is what y= ou are missing. Again read https://wg21.link/cwg1228 which talks about this not being a def= ect in the C++ standard; this is how the standard is written. Anyways clang's bug report is https://github.com/llvm/llvm-project/issues/2= 8016 . >implying the the second overload is not even viable so how can it make the= call ambiguous. I should note that is not have overload resolution works either.=