// RUN: %clang_cc1 -std=c++23 -verify -fsyntax-only %s template constexpr bool is_same = false; template constexpr bool is_same = true; void f() { int y; static_assert(is_same decltype((x)) { return x; }())>); static_assert(is_same decltype((x)) { return x; }())>); static_assert(is_same decltype((y)) { return y; }())>); static_assert(is_same decltype((y)) { return y; }())>); static_assert(is_same decltype((y)) { return y; }())>); static_assert(is_same decltype((y)) { return y; }())>); auto ref = [&x = y]( decltype([&](decltype(x)) { return 0; }) y) { return x; }; } void test_noexcept() { int y; static_assert(noexcept([x = 1] noexcept(is_same) {}())); static_assert(noexcept([x = 1] mutable noexcept(is_same) {}())); static_assert(noexcept([y] noexcept(is_same) {}())); static_assert(noexcept([y] mutable noexcept(is_same) {}())); static_assert(noexcept([=] noexcept(is_same) {}())); static_assert(noexcept([=] mutable noexcept(is_same) {}())); static_assert(noexcept([&] noexcept(is_same) {}())); static_assert(noexcept([&] mutable noexcept(is_same) {}())); } template void test_requires() { int x; [x = 1]() requires is_same {} (); [x = 1]() mutable requires is_same {} (); [x]() requires is_same {} (); [x]() mutable requires is_same {} (); [=]() requires is_same {} (); [=]() mutable requires is_same {} (); [&]() requires is_same {} (); [&]() mutable requires is_same {} (); [&x]() requires is_same {} (); [&x]() mutable requires is_same {} (); [x = 1]() requires is_same {} (); [x = 1]() mutable requires is_same {} (); } void use() { test_requires(); } void err() { int y, z; (void)[x = 1] requires(is_same) {}; (void)[x = 1]{}; (void)[=]{}; (void)[z]{}; } void gnu_attributes() { int y; (void)[=]() __attribute__((diagnose_if(!is_same, "wrong type", "warning"))){}(); // expected-warning@-1 {{wrong type}} expected-note@-1{{'diagnose_if' attribute on 'operator()'}} (void)[=]() __attribute__((diagnose_if(!is_same, "wrong type", "warning"))){}(); (void)[=]() __attribute__((diagnose_if(!is_same, "wrong type", "warning"))) mutable {}(); (void)[=]() __attribute__((diagnose_if(!is_same, "wrong type", "warning"))) mutable {}(); // expected-warning@-1 {{wrong type}} expected-note@-1{{'diagnose_if' attribute on 'operator()'}} (void)[x=1]() __attribute__((diagnose_if(!is_same, "wrong type", "warning"))){}(); // expected-warning@-1 {{wrong type}} expected-note@-1{{'diagnose_if' attribute on 'operator()'}} (void)[x=1]() __attribute__((diagnose_if(!is_same, "wrong type", "warning"))){}(); (void)[x=1]() __attribute__((diagnose_if(!is_same, "wrong type", "warning"))) mutable {}(); (void)[x=1]() __attribute__((diagnose_if(!is_same, "wrong type", "warning"))) mutable {}(); // expected-warning@-1 {{wrong type}} expected-note@-1{{'diagnose_if' attribute on 'operator()'}} } void nested() { int x, y, z; (void)[&]( decltype([&]( decltype([=]( decltype([&]( decltype([&](decltype(x)) {})) {})) {})) {})){}; (void)[&]( decltype([&]( decltype([&]( decltype([&]( decltype([&](decltype(y)) {})) {})) {})) {})){}; (void)[=]( decltype([=]( decltype([=]( decltype([=]( decltype([&] {})) {})) {})) {})){}; } template void dependent(U&& u) { [&]() requires is_same {}(); } template void dependent_init_capture(T x = 0) { [ y = x + 1, x ]() mutable -> decltype(y + x) requires(is_same && is_same) { return y; } (); [ y = x + 1, x ]() -> decltype(y + x) requires(is_same && is_same) { return y; } (); } template struct extract_type { using type = T; }; template void dependent_variadic_capture(T... x) { [... y = x, x... ](auto...) mutable -> typename extract_type::type requires((is_same && ...) && (is_same && ...)) { return 0; } (x...); [... y = x, x... ](auto...) -> typename extract_type::type requires((is_same && ...) && (is_same && ...)) { return 0; } (x...); } void test_dependent() { int v = 0; int & r = v; const int & cr = v; dependent(v); dependent(r); dependent(cr); dependent_init_capture(0); dependent_variadic_capture(1, 2, 3, 4); } void check_params() { int i = 0; int &j = i; (void)[=](decltype((j)) jp, decltype((i)) ip) { static_assert(is_same); static_assert(is_same); static_assert(is_same); static_assert(is_same); }; (void)[=](decltype((j)) jp, decltype((i)) ip) mutable { static_assert(is_same); static_assert(is_same); static_assert(is_same); static_assert(is_same); static_assert(is_same); static_assert(is_same); }; (void)[a = 0](decltype((a)) ap) mutable { static_assert(is_same); static_assert(is_same); static_assert(is_same); }; (void)[a = 0](decltype((a)) ap) { static_assert(is_same); static_assert(is_same); static_assert(is_same); }; } template void check_params_tpl() { T i = 0; T &j = i; (void)[=](decltype((j)) jp, decltype((i)) ip) { static_assert(is_same); static_assert(is_same); static_assert(is_same); static_assert(is_same); }; (void)[=](decltype((j)) jp, decltype((i)) ip) mutable { static_assert(is_same); static_assert(is_same); static_assert(is_same); static_assert(is_same); static_assert(is_same); static_assert(is_same); }; (void)[a = 0](decltype((a)) ap) mutable { static_assert(is_same); static_assert(is_same); static_assert(is_same); }; (void)[a = 0](decltype((a)) ap) { static_assert(is_same); static_assert(is_same); static_assert(is_same); }; } namespace GH61267 { template concept C = true; template void f(int) { int i; [i](P) {}(0); i = 4; } void test() { f(0); } } namespace GH65067 { template class a { public: template void c(b f) { d(f)(0); } template auto d(b f) { return [f = f](auto arg) -> a { return {}; }; } }; a e; auto fn1() { e.c([](int) {}); } } namespace GH63675 { template _Tp __declval(); struct __get_tag { template void operator()(_Tag); }; template struct __basic_sender { using __tag_t = decltype(__declval<_ImplFn>()(__declval<__get_tag>())); _ImplFn __impl_; }; auto __make_basic_sender = []( _Children... __children) { return __basic_sender{[... __children = __children]( _Fun __fun) -> decltype(__fun(__children...)) {}}; }; void __trans_tmp_1() { __make_basic_sender(__trans_tmp_1); } } namespace GH115931 { struct Range {}; template struct LengthPercentage {}; void reflectSum() { Range resultR; [&] (auto) -> LengthPercentage { return {}; }(0); } } // namespace GH115931 namespace GH47400 { struct Foo {}; template struct Arr {}; template struct S {}; constexpr void foo() { constexpr Foo f; [&]() { [&](Arr) {}({}); // f constitutes an ODR-use }.template operator()<42>(); constexpr int C = 1; [] { [](S) { }({}); // ... while C doesn't }(); } } // namespace GH47400 namespace GH84961 { template void g(const T &t) {} template void f(const T &t) { [t] { g(t); }(); } void h() { f(h); } } // namespace GH84961