This fixes the core issue described in P3579, following the design intent of P0522 to not introduce any new cases where a template template parameter match is allowed for a template which is not valid for all possible uses. With this patch, narrowing conversions are disallowed for TTP matching. This reuses the existing machinery for diagnosing narrowing in a converted constant expression. Since P0522 is a DR and we apply it all the way back to C++98, this brings that machinery to use in older standards, in this very narrow scope of TTP matching. This still doesn't solve the ambiguity when partial ordering NTTPs of different integral types, this is blocked by a different bug which will be fixed in a subsequent patch (but the test cases are added).
26 lines
1.3 KiB
C++
26 lines
1.3 KiB
C++
// RUN: %clang_cc1 -fsyntax-only -verify=expected,precxx17,precxx20 %std_cxx98-14 %s
|
|
// RUN: %clang_cc1 -fsyntax-only -verify=expected,cxx17,precxx20 -std=c++17 %s
|
|
// RUN: %clang_cc1 -fsyntax-only -verify=expected,cxx20 %std_cxx20- %s
|
|
|
|
template<typename T, T Value> struct Constant;
|
|
// FIXME: bad location precxx20-error@-1 {{a non-type template parameter cannot have type 'float'}}
|
|
// expected-note@-2 {{template parameter is declared here}}
|
|
// cxx20-note@-3 {{template parameter is declared here}}
|
|
|
|
Constant<int, 5> *c1;
|
|
|
|
int x;
|
|
float f(int, double);
|
|
|
|
Constant<int&, x> *c2;
|
|
Constant<int*, &x> *c3;
|
|
Constant<float (*)(int, double), f> *c4;
|
|
Constant<float (*)(int, double), &f> *c5;
|
|
|
|
Constant<float (*)(int, int), f> *c6; // precxx17-error {{non-type template argument of type 'float (int, double)' cannot be converted to a value of type 'float (*)(int, int)'}} \
|
|
cxx17-error {{value of type 'float (int, double)' is not implicitly convertible to 'float (*)(int, int)'}} \
|
|
cxx20-error {{value of type 'float (int, double)' is not implicitly convertible to 'float (*)(int, int)'}}
|
|
|
|
Constant<float, 0> *c7; // precxx20-note {{while substituting}} \
|
|
cxx20-error {{conversion from 'int' to 'float' is not allowed in a converted constant expression}}
|