1 // RUN: %clang_cc1 -std=c++20 %s -verify
2
3
4 template <auto> struct Nothing {};
__anona4a563870102() 5 Nothing<[]() { return 0; }()> nothing;
6
7 template <typename> struct NothingT {};
__anona4a563870202() 8 Nothing<[]() { return 0; }> nothingT;
9
10 template <typename T>
__anona4a563870302null11 concept True = [] { return true; }();
12 static_assert(True<int>);
13
__anona4a563870402null14 static_assert(sizeof([] { return 0; }));
__anona4a563870502null15 static_assert(sizeof([] { return 0; }()));
16
__anona4a563870602null17 void f() noexcept(noexcept([] { return 0; }()));
18
__anona4a563870702null19 using a = decltype([] { return 0; });
__anona4a563870802null20 using b = decltype([] { return 0; }());
__anona4a563870902null21 using c = decltype([]() noexcept(noexcept([] { return 0; }())) { return 0; });
__anona4a563870a02null22 using d = decltype(sizeof([] { return 0; }));
23
24 template <auto T>
25 int unique_test1();
__anona4a563870c02()26 static_assert(&unique_test1<[](){}> != &unique_test1<[](){}>);
27
28 template <class T>
__anona4a563870d02() 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>
__anona4a563870e02null34 auto foo(decltype([] {
35 return [] { return T(); }();
36 })) {}
37
test()38 void test() {
39 foo<int>({});
40 }
41
42 template <typename T>
43 struct C {
44 template <typename U>
__anona4a563871002C45 auto foo(decltype([] {
46 return [] { return T(); }();
47 })) {}
48 };
49
test2()50 void test2() {
51 C<int>{}.foo<long>({});
52 }
53
54 namespace PR52073 {
55 // OK, these are distinct functions not redefinitions.
__anona4a563871202null56 template<typename> void f(decltype([]{})) {} // expected-note {{candidate}}
__anona4a563871302null57 template<typename> void f(decltype([]{})) {} // expected-note {{candidate}}
use_f()58 void use_f() { f<int>({}); } // expected-error {{ambiguous}}
59
60 // Same.
g(const char (*)[([]{})()])61 template<int N> void g(const char (*)[([]{ return N; })()]) {} // expected-note {{candidate}}
g(const char (*)[([]{})()])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.
use_g()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 {
__anona4a563871602GH51416::A72 void spam(decltype([] {}));
73 };
74
75 template <class T>
__anona4a563871702null76 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>
__anona4a563871802GH51416::B81 void spam(decltype([] {}));
82 };
83
84 template <class T>
__anona4a563871902null85 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}}
foo_tGH50376::foo_t93 foo_t(T ptr) {} // expected-note{{candidate constructor}}
94 };
95
96 template <typename T>
__anona4a563871a02(int) 97 using alias = foo_t<T, decltype([](int) { return 0; })>;
98
99 template <typename T>
fun(T const & 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
f()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 {
__anona4a563871b02null112 template <class T> void spam(decltype([] {}) (*s)[sizeof(T)] = nullptr) {}
foo()113 void foo() {
114 spam<int>();
115 }
116 } // namespace GH51414
117
118 namespace GH51641 {
119 template <class T>
__anona4a563871c02(T) 120 void foo(decltype(+[](T) {}) lambda, T param);
121 static_assert(!__is_same(decltype(foo<int>), void));
122 } // namespace GH51641
123