llvm / llvm-project

The LLVM Project is a collection of modular and reusable compiler and toolchain technologies.
http://llvm.org
Other
27.84k stars 11.47k forks source link

clang fails to diagnose initializer list narrowing in constructor call during template instantiation #44676

Open efriedma-quic opened 4 years ago

efriedma-quic commented 4 years ago
Bugzilla Link 45331
Version unspecified
OS Windows NT
CC @tambry,@zygoloid

Extended Description

struct A { signed char a; constexpr A(signed char a) : a(a) {} };
template<int x> constexpr A f(int y, int (*z)[A{x}.a] = 0) { return A(1); }
template<int x> constexpr A f(char* y) { return A(2); }
static_assert(f<257>(0).a == 2, "Should pick second overload");

gcc accepts, clang rejects. I think gcc is right?

ec04fc15-fa35-46f2-80e1-5d271f2ef708 commented 4 years ago

Reduced slightly:

struct A { A(char); };
template<int x> A a = A{x};
template A a<257>; // ill-formed, but clang accepts
xgupta commented 1 year ago

godbolt link - https://godbolt.org/z/fbWscjsGx.

clang produces a warning for int to char conversion while gcc gives an error for narrowing conversion for the above test case. CheckImplicitConversion of SemaChecking.cpp might be relevent here?

shafik commented 1 year ago

We still pick the first overload: https://godbolt.org/z/EPf3Gqzcv

but @zygoloid example we no longer accept.

zygoloid commented 1 year ago

but @zygoloid example we no longer accept.

I'm not seeing that: https://godbolt.org/z/18Eos4G3M (we should reject under -pedantic-errors at least; and we do outside of template instantiation).