From: Jason Merrill Date: Tue, 8 Jun 2021 13:19:58 +0000 (-0400) Subject: c++: braced-list overload resolution [PR100963] X-Git-Tag: releases/gcc-11.2.0~276 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=5af06ce836d4d8d1654db3855db8b86a994faf49;p=thirdparty%2Fgcc.git c++: braced-list overload resolution [PR100963] My PR969626 patch made us ignore template candidates when there's a perfect non-template candidate. In this case, we were considering B(int) a perfect match for B({0}), but the brace elision makes it imperfect. PR c++/100963 gcc/cp/ChangeLog: * call.c (perfect_conversion_p): Check check_narrowing. gcc/testsuite/ChangeLog: * g++.dg/cpp0x/initlist124.C: New test. --- diff --git a/gcc/cp/call.c b/gcc/cp/call.c index 4c4cb5d04916..4f1565dc68f3 100644 --- a/gcc/cp/call.c +++ b/gcc/cp/call.c @@ -5878,6 +5878,9 @@ perfect_conversion_p (conversion *conv) next_conversion (conv)->type)) return false; } + if (conv->check_narrowing) + /* Brace elision is imperfect. */ + return false; return true; } diff --git a/gcc/testsuite/g++.dg/cpp0x/initlist124.C b/gcc/testsuite/g++.dg/cpp0x/initlist124.C new file mode 100644 index 000000000000..45dcbb303e29 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp0x/initlist124.C @@ -0,0 +1,13 @@ +// PR c++/100963 +// { dg-do compile { target c++11 } } + +#include + +struct B { + B(int) = delete; + template B(std::initializer_list); +}; + +int main() { + B({0}); +}