From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id BD2E339540F2; Mon, 3 May 2021 17:59:19 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org BD2E339540F2 From: "ppalka at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug c++/100396] [11.1 regression] The template function overload is not selected correctly Date: Mon, 03 May 2021 17:59:19 +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: 11.1.0 X-Bugzilla-Keywords: rejects-valid X-Bugzilla-Severity: normal X-Bugzilla-Who: ppalka at gcc dot gnu.org X-Bugzilla-Status: RESOLVED X-Bugzilla-Resolution: INVALID 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: Mon, 03 May 2021 17:59:19 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D100396 --- Comment #3 from Patrick Palka --- (In reply to vopl from comment #2) > Please, try this, also failed >=20 > /////////0/////////1/////////2/////////3/////////4/////////5/////////6///= //// > //7 > template struct Checker > { > using Some =3D decltype(F{}(Args{}...)); > }; >=20 > template concept valid =3D > requires { typename Checker::Some; }; >=20 > /////////0/////////1/////////2/////////3/////////4/////////5/////////6///= //// > //7 > template auto ovr(F f, Args... args) > requires valid > { > return ovr(int{}, f, args...); // a second ovr is expected > to be called, but the compiler tries to call this ovr again. Collision > between 'int' and 'F' is ignored, extra Args provided to call > } >=20 > template auto ovr(int, F f, Args... args) > { > return f(args...); > } >=20 > /////////0/////////1/////////2/////////3/////////4/////////5/////////6///= //// > //7 > void use() > { > ovr([]{}); > } >=20 >=20 > $ g++-11.1.0 -std=3Dc++20 -c src.cpp=20 > src.cpp: In instantiation of 'struct Checker, > use():: >': > src.cpp:8:25: required by substitution of 'template Args> auto ovr(F, Args ...) requires valid [with F =3D > use()::; Args =3D {use()::}]' > src.cpp:14:27: required from 'auto ovr(F, Args ...) requires valid Args ...> [with F =3D use()::; Args =3D {}]' > src.cpp:25:8: required from here > src.cpp:4:30: error: no match for call to '(use()::) > (use()::)' > 4 | using Some =3D decltype(F{}(Args{}...)); > | ~~~^~~~~~~~~~~ > src.cpp:4:30: note: candidate: 'void (*)()' (conversion) > src.cpp:4:30: note: candidate expects 1 argument, 2 provided > src.cpp:25:9: note: candidate: 'use()::' > 25 | ovr([]{}); > | ^ > src.cpp:25:9: note: candidate expects 0 arguments, 1 provided >=20 > ---------- > IMHO, the problem is not caused by concepts, but caused by corrupted > overloading selection mechanic. Please, take a look at the collision betw= een > argument 'int{}' and first template parameter specified as 'F'. Next, no > SFINAE expected in this case due to correct overloading, but overloading > failed and SFINAE happens. Thanks. Although the collision between 'int{}' and the template argument for 'F' do= es mean that the first overload ultimately isn't viable, the compiler as per CWG2369 first needs to check the overload's constraints (using the provided/deduced template arguments) _before_ checking whether 'int' is convertible to 'F', and it's during this constraint checking we hit the hard error. So as far as I can tell, the compiler is behaving as specified. See also PR99599 and its related PRs.=