1 // RUN: %clang_cc1 -std=c++20 %s -Wno-c++2b-extensions -verify
2 // RUN: %clang_cc1 -std=c++2b %s -verify
5 template <auto> struct Nothing
{};
6 Nothing
<[]() { return 0; }()> nothing
;
8 template <typename
> struct NothingT
{};
9 Nothing
<[]() { return 0; }> nothingT
;
12 concept True
= [] { return true; }();
13 static_assert(True
<int>);
15 static_assert(sizeof([] { return 0; }));
16 static_assert(sizeof([] { return 0; }()));
18 void f() noexcept(noexcept([] { return 0; }()));
20 using a
= decltype([] { return 0; });
21 using b
= decltype([] { return 0; }());
22 using c
= decltype([]() noexcept(noexcept([] { return 0; }())) { return 0; });
23 using d
= decltype(sizeof([] { return 0; }));
27 static_assert(&unique_test1
<[](){}> != &unique_test1
<[](){}>);
30 auto g(T
) -> decltype([]() { T::invalid
; } ());
31 auto e
= g(0); // expected-error{{no matching function for call}}
32 // expected-note@-2 {{substitution failure}}
35 auto foo(decltype([] {
36 return [] { return T(); }();
46 auto foo(decltype([] {
47 return [] { return T(); }();
52 C
<int>{}.foo
<long>({});
56 // OK, these are distinct functions not redefinitions.
57 template<typename
> void f(decltype([]{})) {} // expected-note {{candidate}}
58 template<typename
> void f(decltype([]{})) {} // expected-note {{candidate}}
59 void use_f() { f
<int>({}); } // expected-error {{ambiguous}}
62 template<int N
> void g(const char (*)[([]{ return N
; })()]) {} // expected-note {{candidate}}
63 template<int N
> void g(const char (*)[([]{ return N
; })()]) {} // expected-note {{candidate}}
64 void use_g() { g
<6>(&"hello"); } // expected-error {{ambiguous}}
71 void spam(decltype([] {}));
75 void A
<T
>::spam(decltype([] {})) // expected-error{{out-of-line definition of 'spam' does not match}}
80 void spam(decltype([] {}));
84 void B::spam(decltype([] {})) {} // expected-error{{out-of-line definition of 'spam' does not match}}
86 } // namespace GH51416
90 template <typename T
, typename Fn
>
91 struct foo_t
{ // expected-note 2{{candidate constructor}}
92 foo_t(T ptr
) {} // expected-note{{candidate constructor}}
96 using alias
= foo_t
<T
, decltype([](int) { return 0; })>;
99 auto fun(T
const &t
) -> alias
<T
> {
100 return alias
<T
>{t
}; // expected-error{{no viable conversion from returned value of type 'alias<...>'}}
105 auto const error
= fun(i
); // expected-note{{in instantiation}}
108 } // namespace GH50376
111 template <class T
> void spam(decltype([] {}) (*s
)[sizeof(T
)] = nullptr) {}
115 } // namespace GH51414
119 void foo(decltype(+[](T
) {}) lambda
, T param
);
120 static_assert(!__is_same(decltype(foo
<int>), void));
121 } // namespace GH51641
123 namespace StaticLambdas
{
124 template <auto> struct Nothing
{};
125 Nothing
<[]() static { return 0; }()> nothing
;
127 template <typename
> struct NothingT
{};
128 Nothing
<[]() static { return 0; }> nothingT
;
130 template <typename T
>
131 concept True
= [] static { return true; }();
132 static_assert(True
<int>);
134 static_assert(sizeof([] static { return 0; }));
135 static_assert(sizeof([] static { return 0; }()));
137 void f() noexcept(noexcept([] static { return 0; }()));
139 using a
= decltype([] static { return 0; });
140 using b
= decltype([] static { return 0; }());
141 using c
= decltype([]() static noexcept(noexcept([] { return 0; }())) { return 0; });
142 using d
= decltype(sizeof([] static { return 0; }));
146 namespace lambda_in_trailing_decltype
{
147 auto x
= ([](auto) -> decltype([] {}()) {}(0), 2);