aboutsummaryrefslogtreecommitdiff
path: root/gcc/testsuite/g++.dg/cpp2a/lambda-uneval2.C
blob: d8b20bdc2a42a350d0915ef3c85fc11fd70cd553 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
// { dg-do compile { target c++20 } }

// ill-formed, no diagnostic required: the two expressions are
// functionally equivalent but not equivalent
template <int N> void foo(const char (&s)[([]{}, N)]);
template <int N> void foo(const char (&s)[([]{}, N)]);

// two different declarations because the non-dependent portions are not
// considered equivalent
template <class T> void spam(decltype([]{}) (*s)[sizeof(T)]);
template <class T> void spam(decltype([]{}) (*s)[sizeof(T)]);

template <class T>
using A = decltype([] { });
// A<int> and A<char> refer to different closure types

template <class T>
auto f(T) -> decltype([]() { T::invalid; } ()); // { dg-error "invalid" }
void f(...);

template <class T, unsigned = sizeof([]() { T::invalid; })> // { dg-error "invalid" }
void g(T);
void g(...);

template <class T>
auto h(T) -> decltype([x = T::invalid]() { });
void h(...);

template <class T>
auto i(T) -> decltype([]() -> typename T::invalid { });
void i(...);

template <class T>
auto j(T t) -> decltype([](auto x) -> decltype(x.invalid) { } (t));
void j(...);

template <class,class> struct different {};
template <class T> struct different<T,T> { typename T::invalid t; };

template <class,class> struct same;
template <class T> struct same<T,T> {};

int main()
{
  foo<1>("");	 // { dg-error "ambiguous" }
  spam<char>(nullptr);		// { dg-error "ambiguous" }
  different<A<int>,A<char>>();
  same<A<int>,A<int>>();
  f(0); // error: invalid expression not part of the immediate context
  g(0); // error: invalid expression not part of the immediate context
  h(0); // error: invalid expression not part of the immediate context
  i(0); // error: invalid expression not part of the immediate context
  j(0); // deduction fails on #1, calls #2
}