[clang][lex] NFCI: Use DirectoryEntryRef in ModuleMap::inferFrameworkModule()
[llvm-project.git] / clang / test / SemaTemplate / concepts-lambda.cpp
blob8a184cbf4e9bc233b3f749aa482303d95a447a29
1 // RUN: %clang_cc1 -std=c++20 -verify %s
2 // RUN: %clang_cc1 -std=c++20 -verify %s -triple powerpc64-ibm-aix
4 namespace GH57945 {
5 template<typename T>
6 concept c = true;
8 template<typename>
9 auto f = []() requires c<void> {
12 void g() {
13 f<int>();
17 namespace GH57945_2 {
18 template<typename>
19 concept c = true;
21 template<typename T>
22 auto f = [](auto... args) requires c<T> {
25 template <typename T>
26 auto f2 = [](auto... args)
27 requires (sizeof...(args) > 0)
28 {};
30 void g() {
31 f<void>();
32 f2<void>(5.0);
36 namespace GH57958 {
37 template<class> concept C = true;
38 template<int> constexpr bool v = [](C auto) { return true; }(0);
39 int _ = v<0>;
41 namespace GH57958_2 {
42 template<class> concept C = true;
43 template<int> constexpr bool v = [](C auto...) { return true; }(0);
44 int _ = v<0>;
47 namespace GH57971 {
48 template<typename>
49 concept any = true;
51 template<typename>
52 auto f = [](any auto) {
55 using function_ptr = void(*)(int);
56 function_ptr ptr = f<void>;
59 // GH58368: A lambda defined in a concept requires we store
60 // the concept as a part of the lambda context.
61 namespace LambdaInConcept {
62 using size_t = unsigned long;
64 template<size_t...Ts>
65 struct IdxSeq{};
67 template <class T, class... Ts>
68 concept NotLike = true;
70 template <size_t, class... Ts>
71 struct AnyExcept {
72 template <NotLike<Ts...> T> operator T&() const;
73 template <NotLike<Ts...> T> operator T&&() const;
76 template <class T>
77 concept ConstructibleWithN = (requires {
78 []<size_t I, size_t... Idxs>
79 (IdxSeq<I, Idxs...>)
80 requires requires { T{AnyExcept<I, T>{}}; }
81 { }
82 (IdxSeq<1,2,3>{});
83 });
85 struct Foo {
86 int i;
87 double j;
88 char k;
91 static_assert(ConstructibleWithN<Foo>);
95 // GH60642 reported an assert being hit, make sure we don't assert.
96 namespace GH60642 {
97 template<auto Q> concept C = requires { Q.template operator()<float>(); };
98 template<class> concept D = true;
99 static_assert(C<[]<D>{}>); // ok
100 template<class> concept E = C<[]<D>{}>;
101 static_assert(E<int>); // previously Asserted.
103 // ensure we properly diagnose when "D" is false.
104 namespace DIsFalse {
105 template<auto Q> concept C = requires { Q.template operator()<float>(); };
106 template<class> concept D = false;
107 static_assert(C<[]<D>{}>);
108 // expected-error@-1{{static assertion failed}}
109 // expected-note@-2{{does not satisfy 'C'}}
110 // expected-note@-5{{because 'Q.template operator()<float>()' would be invalid: no matching member function for call to 'operator()'}}
111 template<class> concept E = C<[]<D>{}>;
112 static_assert(E<int>);
113 // expected-error@-1{{static assertion failed}}
114 // expected-note@-2{{because 'int' does not satisfy 'E'}}
115 // expected-note@-4{{does not satisfy 'C'}}
116 // expected-note@-11{{because 'Q.template operator()<float>()' would be invalid: no matching member function for call to 'operator()'}}