https://gcc.gnu.org/bugzilla/show_bug.cgi?id=122851
Bug ID: 122851
Summary: Ambiguous function call with an empty initializer list
as an explicit template argument is accepted in favor
of the last declaration
Product: gcc
Version: 15.2.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: gulackeg at gmail dot com
Target Milestone: ---
Test code:
// https://godbolt.org/z/fKE6M4Ybq
struct A {};
struct B {};
namespace test1 {
template <A> A f();
template <B> B f();
// - ❌ GCC: OK
// - ✅ Clang:
// - error: call to 'f' is ambiguous
// - note: candidate function [with $0 = A{}]
// - note: candidate function [with $0 = B{}]
using T = decltype(f<{}>());
using T = B;
} // namespace test1
namespace test2 {
template <B> B f();
template <A> A f();
// - ❌ GCC: OK
// - ✅ Clang:
// - error: call to 'f' is ambiguous
// - note: candidate function [with $0 = B{}]
// - note: candidate function [with $0 = A{}]
using T = decltype(f<{}>());
using T = A;
} // namespace test2