1 // RUN: %clang_cc1 -std=c++20 %s -verify
2 
3 
4 template <auto> struct Nothing {};
5 Nothing<[]() { return 0; }()> nothing;
6 
7 template <typename> struct NothingT {};
8 Nothing<[]() { return 0; }> nothingT;
9 
10 template <typename T>
11 concept True = [] { return true; }();
12 static_assert(True<int>);
13 
14 static_assert(sizeof([] { return 0; }));
15 static_assert(sizeof([] { return 0; }()));
16 
17 void f()  noexcept(noexcept([] { return 0; }()));
18 
19 using a = decltype([] { return 0; });
20 using b = decltype([] { return 0; }());
21 using c = decltype([]() noexcept(noexcept([] { return 0; }())) { return 0; });
22 using d = decltype(sizeof([] { return 0; }));
23 
24 template <auto T>
25 int unique_test1();
26 static_assert(&unique_test1<[](){}> != &unique_test1<[](){}>);
27 
28 template <class T>
29 auto g(T) -> decltype([]() { T::invalid; } ());
30 auto e = g(0); // expected-error{{no matching function for call}}
31 // expected-note@-2 {{substitution failure}}
32 
33 template <typename T>
34 auto foo(decltype([] {
35   return [] { return T(); }();
36 })) {}
37 
38 void test() {
39   foo<int>({});
40 }
41 
42 template <typename T>
43 struct C {
44   template <typename U>
45   auto foo(decltype([] {
46     return [] { return T(); }();
47   })) {}
48 };
49 
50 void test2() {
51   C<int>{}.foo<long>({});
52 }
53 
54 namespace PR52073 {
55 // OK, these are distinct functions not redefinitions.
56 template<typename> void f(decltype([]{})) {} // expected-note {{candidate}}
57 template<typename> void f(decltype([]{})) {} // expected-note {{candidate}}
58 void use_f() { f<int>({}); } // expected-error {{ambiguous}}
59 
60 // Same.
61 template<int N> void g(const char (*)[([]{ return N; })()]) {} // expected-note {{candidate}}
62 template<int N> void g(const char (*)[([]{ return N; })()]) {} // expected-note {{candidate}}
63 // FIXME: We instantiate the lambdas into the context of the function template,
64 //  so we think they're dependent and can't evaluate a call to them.
65 void use_g() { g<6>(&"hello"); } // expected-error {{no matching function}}
66 }
67 
68 namespace GH51416 {
69 
70 template <class T>
71 struct A {
72   void spam(decltype([] {}));
73 };
74 
75 template <class T>
76 void A<T>::spam(decltype([] {})) // expected-error{{out-of-line definition of 'spam' does not match}}
77 {}
78 
79 struct B {
80   template <class T>
81   void spam(decltype([] {}));
82 };
83 
84 template <class T>
85 void B::spam(decltype([] {})) {} // expected-error{{out-of-line definition of 'spam' does not match}}
86 
87 } // namespace GH51416
88 
89 namespace GH50376 {
90 
91 template <typename T, typename Fn>
92 struct foo_t {    // expected-note 2{{candidate constructor}}
93   foo_t(T ptr) {} // expected-note{{candidate constructor}}
94 };
95 
96 template <typename T>
97 using alias = foo_t<T, decltype([](int) { return 0; })>;
98 
99 template <typename T>
100 auto fun(T const &t) -> alias<T> {
101   return alias<T>{t}; // expected-error{{no viable conversion from returned value of type 'alias<...>'}}
102 }
103 
104 void f() {
105   int i;
106   auto const error = fun(i); // expected-note{{in instantiation}}
107 }
108 
109 } // namespace GH50376
110 
111 namespace GH51414 {
112 template <class T> void spam(decltype([] {}) (*s)[sizeof(T)] = nullptr) {}
113 void foo() {
114   spam<int>();
115 }
116 } // namespace GH51414
117 
118 namespace GH51641 {
119 template <class T>
120 void foo(decltype(+[](T) {}) lambda, T param);
121 static_assert(!__is_same(decltype(foo<int>), void));
122 } // namespace GH51641
123