108 lines · cpp
1// RUN: %clang_cc1 -std=c++03 %s -verify -Wno-c++23-extensions -Wno-c++20-extensions -Wno-c++17-extensions -Wno-c++14-extensions -Wno-c++11-extensions2// RUN: %clang_cc1 -std=c++11 %s -verify=expected,cxx11 -Wno-c++23-extensions -Wno-c++20-extensions -Wno-c++17-extensions -Wno-c++14-extensions3// RUN: %clang_cc1 -std=c++14 %s -verify -Wno-c++23-extensions -Wno-c++20-extensions -Wno-c++17-extensions4// RUN: %clang_cc1 -std=c++17 %s -verify -Wno-c++23-extensions -Wno-c++20-extensions5// RUN: %clang_cc1 -std=c++20 %s -verify -Wno-c++23-extensions6// RUN: %clang_cc1 -std=c++23 %s -verify7 8auto LL0 = [] {};9auto LL1 = []() {};10auto LL2 = []() mutable {};11#if __cplusplus >= 201103L12auto LL3 = []() constexpr {}; // cxx11-error {{return type 'void' is not a literal type}}13#endif14 15#if __cplusplus >= 201103L16auto L0 = [] constexpr {}; // cxx11-error {{return type 'void' is not a literal type}}17#endif18auto L1 = [] mutable {};19#if __cplusplus >= 201103L20auto L2 = [] noexcept {};21auto L3 = [] constexpr mutable {}; // cxx11-error {{return type 'void' is not a literal type}}22auto L4 = [] mutable constexpr {}; // cxx11-error {{return type 'void' is not a literal type}}23auto L5 = [] constexpr mutable noexcept {}; // cxx11-error {{return type 'void' is not a literal type}}24#endif25auto L6 = [s = 1] mutable {};26#if __cplusplus >= 201103L27auto L7 = [s = 1] constexpr mutable noexcept {}; // cxx11-error {{return type 'void' is not a literal type}}28#endif29auto L8 = [] -> bool { return true; };30auto L9 = []<typename T> { return true; };31#if __cplusplus >= 201103L32auto L10 = []<typename T> noexcept { return true; };33#endif34auto L11 = []<typename T> -> bool { return true; };35#if __cplusplus >= 202002L36auto L12 = [] consteval {};37auto L13 = []() requires true {}; // expected-error{{non-templated function cannot have a requires clause}}38auto L14 = []<auto> requires true() requires true {};39auto L15 = []<auto> requires true noexcept {};40#endif41auto L16 = [] [[maybe_unused]]{};42 43#if __cplusplus >= 201103L44auto XL0 = [] mutable constexpr mutable {}; // expected-error{{cannot appear multiple times}} cxx11-error {{return type 'void' is not a literal type}}45auto XL1 = [] constexpr mutable constexpr {}; // expected-error{{cannot appear multiple times}} cxx11-error {{return type 'void' is not a literal type}}46auto XL2 = []) constexpr mutable constexpr {}; // expected-error{{expected body of lambda expression}}47auto XL3 = []( constexpr mutable constexpr {}; // expected-error{{invalid storage class specifier}} \48 // expected-error{{function parameter cannot be constexpr}} \49 // expected-error{{a type specifier is required}} \50 // expected-error{{expected ')'}} \51 // expected-note{{to match this '('}} \52 // expected-error{{expected body}} \53 // expected-warning{{duplicate 'constexpr'}}54#endif55 56// http://llvm.org/PR4973657auto XL4 = [] requires true {}; // expected-error{{expected body}}58#if __cplusplus >= 201703L59auto XL5 = []<auto> requires true requires true {}; // expected-error{{expected body}}60auto XL6 = []<auto> requires true noexcept requires true {}; // expected-error{{expected body}}61#endif62 63auto XL7 = []() static static {}; // expected-error {{cannot appear multiple times}}64auto XL8 = []() static mutable {}; // expected-error {{cannot be both mutable and static}}65#if __cplusplus >= 202002L66auto XL9 = []() static consteval {};67#endif68#if __cplusplus >= 201103L69auto XL10 = []() static constexpr {}; // cxx11-error {{return type 'void' is not a literal type}}70#endif71 72auto XL11 = [] static {};73auto XL12 = []() static {};74auto XL13 = []() static extern {}; // expected-error {{expected body of lambda expression}}75auto XL14 = []() extern {}; // expected-error {{expected body of lambda expression}}76 77 78void static_captures() {79 int x;80 auto SC1 = [&]() static {}; // expected-error {{a static lambda cannot have any captures}}81 auto SC4 = [x]() static {}; // expected-error {{a static lambda cannot have any captures}}82 auto SC2 = [&x]() static {}; // expected-error {{a static lambda cannot have any captures}}83 auto SC3 = [y=x]() static {}; // expected-error {{a static lambda cannot have any captures}}84 auto SC5 = [&y = x]() static {}; // expected-error {{a static lambda cannot have any captures}}85 auto SC6 = [=]() static {}; // expected-error {{a static lambda cannot have any captures}}86 struct X {87 int z;88 void f() {89 [this]() static {}(); // expected-error {{a static lambda cannot have any captures}}90 [*this]() static {}(); // expected-error {{a static lambda cannot have any captures}}91 }92 };93}94 95#if __cplusplus >= 201703L96constexpr auto static_capture_constexpr() {97 char n = 'n';98 return [n] static { return n; }(); // expected-error {{a static lambda cannot have any captures}}99}100static_assert(static_capture_constexpr()); // expected-error {{static assertion expression is not an integral constant expression}}101 102constexpr auto capture_constexpr() {103 char n = 'n';104 return [n] { return n; }();105}106static_assert(capture_constexpr());107#endif108