| 1 |
// { dg-do compile { target c++20 } } |
| 2 |
|
| 3 |
// ill-formed, no diagnostic required: the two expressions are |
| 4 |
// functionally equivalent but not equivalent |
| 5 |
template <int N> void foo(const char (&s)[([]{}, N)]); |
| 6 |
template <int N> void foo(const char (&s)[([]{}, N)]); |
| 7 |
|
| 8 |
// two different declarations because the non-dependent portions are not |
| 9 |
// considered equivalent |
| 10 |
template <class T> void spam(decltype([]{}) (*s)[sizeof(T)]); |
| 11 |
template <class T> void spam(decltype([]{}) (*s)[sizeof(T)]); |
| 12 |
|
| 13 |
template <class T> |
| 14 |
using A = decltype([] { }); |
| 15 |
// A<int> and A<char> refer to different closure types |
| 16 |
|
| 17 |
template <class T> |
| 18 |
auto f(T) -> decltype([]() { T::invalid; } ()); // { dg-error "invalid" } |
| 19 |
void f(...); |
| 20 |
|
| 21 |
template <class T, unsigned = sizeof([]() { T::invalid; })> // { dg-error "invalid" } |
| 22 |
void g(T); |
| 23 |
void g(...); |
| 24 |
|
| 25 |
template <class T> |
| 26 |
auto h(T) -> decltype([x = T::invalid]() { }); |
| 27 |
void h(...); |
| 28 |
|
| 29 |
template <class T> |
| 30 |
auto i(T) -> decltype([]() -> typename T::invalid { }); |
| 31 |
void i(...); |
| 32 |
|
| 33 |
template <class T> |
| 34 |
auto j(T t) -> decltype([](auto x) -> decltype(x.invalid) { } (t)); |
| 35 |
void j(...); |
| 36 |
|
| 37 |
template <class,class> struct different {}; |
| 38 |
template <class T> struct different<T,T> { typename T::invalid t; }; |
| 39 |
|
| 40 |
template <class,class> struct same; |
| 41 |
template <class T> struct same<T,T> {}; |
| 42 |
|
| 43 |
int main() |
| 44 |
{ |
| 45 |
foo<1>(""); // { dg-error "ambiguous" } |
| 46 |
spam<char>(nullptr); // { dg-error "ambiguous" } |
| 47 |
different<A<int>,A<char>>(); |
| 48 |
same<A<int>,A<int>>(); |
| 49 |
f(0); // error: invalid expression not part of the immediate context |
| 50 |
g(0); // error: invalid expression not part of the immediate context |
| 51 |
h(0); // error: invalid expression not part of the immediate context |
| 52 |
i(0); // error: invalid expression not part of the immediate context |
| 53 |
j(0); // deduction fails on #1, calls #2 |
| 54 |
} |