122aa3680SCorentin Jabot // RUN: %clang_cc1 -std=c++20 %s -verify 222aa3680SCorentin Jabot 322aa3680SCorentin Jabot 422aa3680SCorentin Jabot template <auto> struct Nothing {}; __anona4a563870102() 522aa3680SCorentin JabotNothing<[]() { return 0; }()> nothing; 622aa3680SCorentin Jabot 722aa3680SCorentin Jabot template <typename> struct NothingT {}; __anona4a563870202() 822aa3680SCorentin JabotNothing<[]() { return 0; }> nothingT; 922aa3680SCorentin Jabot 1022aa3680SCorentin Jabot template <typename T> __anona4a563870302null1122aa3680SCorentin Jabotconcept True = [] { return true; }(); 1222aa3680SCorentin Jabot static_assert(True<int>); 1322aa3680SCorentin Jabot __anona4a563870402null1422aa3680SCorentin Jabotstatic_assert(sizeof([] { return 0; })); __anona4a563870502null1522aa3680SCorentin Jabotstatic_assert(sizeof([] { return 0; }())); 1622aa3680SCorentin Jabot __anona4a563870602null1722aa3680SCorentin Jabotvoid f() noexcept(noexcept([] { return 0; }())); 1822aa3680SCorentin Jabot __anona4a563870702null1922aa3680SCorentin Jabotusing a = decltype([] { return 0; }); __anona4a563870802null2022aa3680SCorentin Jabotusing b = decltype([] { return 0; }()); __anona4a563870902null2122aa3680SCorentin Jabotusing c = decltype([]() noexcept(noexcept([] { return 0; }())) { return 0; }); __anona4a563870a02null2222aa3680SCorentin Jabotusing d = decltype(sizeof([] { return 0; })); 2322aa3680SCorentin Jabot 2422aa3680SCorentin Jabot template <auto T> 2522aa3680SCorentin Jabot int unique_test1(); __anona4a563870c02()2622aa3680SCorentin Jabotstatic_assert(&unique_test1<[](){}> != &unique_test1<[](){}>); 2722aa3680SCorentin Jabot 2822aa3680SCorentin Jabot template <class T> __anona4a563870d02() 2922aa3680SCorentin Jabotauto g(T) -> decltype([]() { T::invalid; } ()); 3022aa3680SCorentin Jabot auto e = g(0); // expected-error{{no matching function for call}} 3122aa3680SCorentin Jabot // expected-note@-2 {{substitution failure}} 327ac308fbSRichard Smith 33*3784e8ccSCorentin Jabot template <typename T> __anona4a563870e02null34*3784e8ccSCorentin Jabotauto foo(decltype([] { 35*3784e8ccSCorentin Jabot return [] { return T(); }(); 36*3784e8ccSCorentin Jabot })) {} 37*3784e8ccSCorentin Jabot test()38*3784e8ccSCorentin Jabotvoid test() { 39*3784e8ccSCorentin Jabot foo<int>({}); 40*3784e8ccSCorentin Jabot } 41*3784e8ccSCorentin Jabot 42*3784e8ccSCorentin Jabot template <typename T> 43*3784e8ccSCorentin Jabot struct C { 44*3784e8ccSCorentin Jabot template <typename U> __anona4a563871002C45*3784e8ccSCorentin Jabot auto foo(decltype([] { 46*3784e8ccSCorentin Jabot return [] { return T(); }(); 47*3784e8ccSCorentin Jabot })) {} 48*3784e8ccSCorentin Jabot }; 49*3784e8ccSCorentin Jabot test2()50*3784e8ccSCorentin Jabotvoid test2() { 51*3784e8ccSCorentin Jabot C<int>{}.foo<long>({}); 52*3784e8ccSCorentin Jabot } 53*3784e8ccSCorentin Jabot 547ac308fbSRichard Smith namespace PR52073 { 557ac308fbSRichard Smith // OK, these are distinct functions not redefinitions. __anona4a563871202null567ac308fbSRichard Smithtemplate<typename> void f(decltype([]{})) {} // expected-note {{candidate}} __anona4a563871302null577ac308fbSRichard Smithtemplate<typename> void f(decltype([]{})) {} // expected-note {{candidate}} use_f()587ac308fbSRichard Smithvoid use_f() { f<int>({}); } // expected-error {{ambiguous}} 597ac308fbSRichard Smith 607ac308fbSRichard Smith // Same. g(const char (*)[([]{})()])617ac308fbSRichard Smithtemplate<int N> void g(const char (*)[([]{ return N; })()]) {} // expected-note {{candidate}} g(const char (*)[([]{})()])627ac308fbSRichard Smithtemplate<int N> void g(const char (*)[([]{ return N; })()]) {} // expected-note {{candidate}} 637ac308fbSRichard Smith // FIXME: We instantiate the lambdas into the context of the function template, 647ac308fbSRichard Smith // so we think they're dependent and can't evaluate a call to them. use_g()657ac308fbSRichard Smithvoid use_g() { g<6>(&"hello"); } // expected-error {{no matching function}} 667ac308fbSRichard Smith } 67*3784e8ccSCorentin Jabot 68*3784e8ccSCorentin Jabot namespace GH51416 { 69*3784e8ccSCorentin Jabot 70*3784e8ccSCorentin Jabot template <class T> 71*3784e8ccSCorentin Jabot struct A { __anona4a563871602GH51416::A72*3784e8ccSCorentin Jabot void spam(decltype([] {})); 73*3784e8ccSCorentin Jabot }; 74*3784e8ccSCorentin Jabot 75*3784e8ccSCorentin Jabot template <class T> __anona4a563871702null76*3784e8ccSCorentin Jabotvoid A<T>::spam(decltype([] {})) // expected-error{{out-of-line definition of 'spam' does not match}} 77*3784e8ccSCorentin Jabot {} 78*3784e8ccSCorentin Jabot 79*3784e8ccSCorentin Jabot struct B { 80*3784e8ccSCorentin Jabot template <class T> __anona4a563871802GH51416::B81*3784e8ccSCorentin Jabot void spam(decltype([] {})); 82*3784e8ccSCorentin Jabot }; 83*3784e8ccSCorentin Jabot 84*3784e8ccSCorentin Jabot template <class T> __anona4a563871902null85*3784e8ccSCorentin Jabotvoid B::spam(decltype([] {})) {} // expected-error{{out-of-line definition of 'spam' does not match}} 86*3784e8ccSCorentin Jabot 87*3784e8ccSCorentin Jabot } // namespace GH51416 88*3784e8ccSCorentin Jabot 89*3784e8ccSCorentin Jabot namespace GH50376 { 90*3784e8ccSCorentin Jabot 91*3784e8ccSCorentin Jabot template <typename T, typename Fn> 92*3784e8ccSCorentin Jabot struct foo_t { // expected-note 2{{candidate constructor}} foo_tGH50376::foo_t93*3784e8ccSCorentin Jabot foo_t(T ptr) {} // expected-note{{candidate constructor}} 94*3784e8ccSCorentin Jabot }; 95*3784e8ccSCorentin Jabot 96*3784e8ccSCorentin Jabot template <typename T> __anona4a563871a02(int) 97*3784e8ccSCorentin Jabotusing alias = foo_t<T, decltype([](int) { return 0; })>; 98*3784e8ccSCorentin Jabot 99*3784e8ccSCorentin Jabot template <typename T> fun(T const & t)100*3784e8ccSCorentin Jabotauto fun(T const &t) -> alias<T> { 101*3784e8ccSCorentin Jabot return alias<T>{t}; // expected-error{{no viable conversion from returned value of type 'alias<...>'}} 102*3784e8ccSCorentin Jabot } 103*3784e8ccSCorentin Jabot f()104*3784e8ccSCorentin Jabotvoid f() { 105*3784e8ccSCorentin Jabot int i; 106*3784e8ccSCorentin Jabot auto const error = fun(i); // expected-note{{in instantiation}} 107*3784e8ccSCorentin Jabot } 108*3784e8ccSCorentin Jabot 109*3784e8ccSCorentin Jabot } // namespace GH50376 110*3784e8ccSCorentin Jabot 111*3784e8ccSCorentin Jabot namespace GH51414 { __anona4a563871b02null112*3784e8ccSCorentin Jabottemplate <class T> void spam(decltype([] {}) (*s)[sizeof(T)] = nullptr) {} foo()113*3784e8ccSCorentin Jabotvoid foo() { 114*3784e8ccSCorentin Jabot spam<int>(); 115*3784e8ccSCorentin Jabot } 116*3784e8ccSCorentin Jabot } // namespace GH51414 117*3784e8ccSCorentin Jabot 118*3784e8ccSCorentin Jabot namespace GH51641 { 119*3784e8ccSCorentin Jabot template <class T> __anona4a563871c02(T) 120*3784e8ccSCorentin Jabotvoid foo(decltype(+[](T) {}) lambda, T param); 121*3784e8ccSCorentin Jabot static_assert(!__is_same(decltype(foo<int>), void)); 122*3784e8ccSCorentin Jabot } // namespace GH51641 123