[clang] Handle __declspec() attributes in using
[llvm-project.git] / clang / test / SemaCXX / lambda-unevaluated.cpp
blobda00cb48a87fd0542f5c391796eff2f3871815a4
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;
11 template <typename T>
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; }));
25 template <auto T>
26 int unique_test1();
27 static_assert(&unique_test1<[](){}> != &unique_test1<[](){}>);
29 template <class T>
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}}
34 template <typename T>
35 auto foo(decltype([] {
36 return [] { return T(); }();
37 })) {}
39 void test() {
40 foo<int>({});
43 template <typename T>
44 struct C {
45 template <typename U>
46 auto foo(decltype([] {
47 return [] { return T(); }();
48 })) {}
51 void test2() {
52 C<int>{}.foo<long>({});
55 namespace PR52073 {
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}}
61 // Same.
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}}
67 namespace GH51416 {
69 template <class T>
70 struct A {
71 void spam(decltype([] {}));
74 template <class T>
75 void A<T>::spam(decltype([] {})) // expected-error{{out-of-line definition of 'spam' does not match}}
78 struct B {
79 template <class T>
80 void spam(decltype([] {}));
83 template <class T>
84 void B::spam(decltype([] {})) {} // expected-error{{out-of-line definition of 'spam' does not match}}
86 } // namespace GH51416
88 namespace GH50376 {
90 template <typename T, typename Fn>
91 struct foo_t { // expected-note 2{{candidate constructor}}
92 foo_t(T ptr) {} // expected-note{{candidate constructor}}
95 template <typename T>
96 using alias = foo_t<T, decltype([](int) { return 0; })>;
98 template <typename T>
99 auto fun(T const &t) -> alias<T> {
100 return alias<T>{t}; // expected-error{{no viable conversion from returned value of type 'alias<...>'}}
103 void f() {
104 int i;
105 auto const error = fun(i); // expected-note{{in instantiation}}
108 } // namespace GH50376
110 namespace GH51414 {
111 template <class T> void spam(decltype([] {}) (*s)[sizeof(T)] = nullptr) {}
112 void foo() {
113 spam<int>();
115 } // namespace GH51414
117 namespace GH51641 {
118 template <class T>
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);