diff options
author | Dimitry Andric <dim@FreeBSD.org> | 2019-08-20 17:59:23 +0000 |
---|---|---|
committer | Dimitry Andric <dim@FreeBSD.org> | 2019-08-20 17:59:23 +0000 |
commit | 9a83721404652cea39e9f02ae3e3b5c964602a5c (patch) | |
tree | 23e9541ce27049a103f6ed046be61592123e02c9 /test/CXX/expr/expr.prim/expr.prim.lambda | |
parent | 676fbe8105eeb6ff4bb2ed261cb212fcfdbe7b63 (diff) |
Notes
Diffstat (limited to 'test/CXX/expr/expr.prim/expr.prim.lambda')
30 files changed, 0 insertions, 1500 deletions
diff --git a/test/CXX/expr/expr.prim/expr.prim.lambda/blocks-irgen.mm b/test/CXX/expr/expr.prim/expr.prim.lambda/blocks-irgen.mm deleted file mode 100644 index 24ce2cd6c198d..0000000000000 --- a/test/CXX/expr/expr.prim/expr.prim.lambda/blocks-irgen.mm +++ /dev/null @@ -1,29 +0,0 @@ -// RUN: %clang_cc1 -std=c++11 -fblocks -emit-llvm -o - -triple x86_64-apple-darwin11.3 %s | FileCheck %s - -namespace PR12746 { - // CHECK: define zeroext i1 @_ZN7PR127462f1EPi - bool f1(int *x) { - // CHECK: store i8* bitcast (i1 (i8*)* @___ZN7PR127462f1EPi_block_invoke to i8*) - bool (^outer)() = ^ { - auto inner = [&]() -> bool { - return x == 0; - }; - return inner(); - }; - return outer(); - } - - // CHECK: define internal zeroext i1 @___ZN7PR127462f1EPi_block_invoke - // CHECK: call zeroext i1 @"_ZZZN7PR127462f1EPiEUb_ENK3$_0clEv" - - bool f2(int *x) { - auto outer = [&]() -> bool { - bool (^inner)() = ^ { - return x == 0; - }; - return inner(); - }; - return outer(); - } -} - diff --git a/test/CXX/expr/expr.prim/expr.prim.lambda/blocks.mm b/test/CXX/expr/expr.prim/expr.prim.lambda/blocks.mm deleted file mode 100644 index 96e8fcd8d3717..0000000000000 --- a/test/CXX/expr/expr.prim/expr.prim.lambda/blocks.mm +++ /dev/null @@ -1,144 +0,0 @@ -// RUN: %clang_cc1 -triple i686-pc-linux -std=c++11 -fblocks %s -verify - -void block_capture_errors() { - __block int var; // expected-note 2{{'var' declared here}} - (void)[var] { }; // expected-error{{__block variable 'var' cannot be captured in a lambda}} - - (void)[=] { var = 17; }; // expected-error{{__block variable 'var' cannot be captured in a lambda}} -} - -void conversion_to_block(int captured) { - int (^b1)(int) = [=](int x) { return x + captured; }; - - const auto lambda = [=](int x) { return x + captured; }; - int (^b2)(int) = lambda; -} - -template<typename T> -class ConstCopyConstructorBoom { -public: - ConstCopyConstructorBoom(ConstCopyConstructorBoom&); - - ConstCopyConstructorBoom(const ConstCopyConstructorBoom&) { - T *ptr = 1; // expected-error{{cannot initialize a variable of type 'float *' with an rvalue of type 'int'}} - } - - void foo() const; -}; - -void conversion_to_block_init(ConstCopyConstructorBoom<int> boom, - ConstCopyConstructorBoom<float> boom2) { - const auto& lambda1([=] { boom.foo(); }); // okay - - const auto& lambda2([=] { boom2.foo(); }); // expected-note{{in instantiation of member function}} - void (^block)(void) = lambda2; -} - - -void nesting() { - int array[7]; // expected-note 2{{'array' declared here}} - [=] () mutable { - [&] { - ^ { - int i = array[2]; - i += array[3]; - }(); - }(); - }(); - - [&] { - [=] () mutable { - ^ { - int i = array[2]; // expected-error{{cannot refer to declaration with an array type inside block}} - i += array[3]; // expected-error{{cannot refer to declaration with an array type inside block}} - }(); - }(); - }(); -} - -namespace overloading { - void bool_conversion() { - if ([](){}) { - } - - bool b = []{}; - b = (bool)[]{}; - } - - void conversions() { - int (*fp)(int) = [](int x) { return x + 1; }; - fp = [](int x) { return x + 1; }; - - typedef int (*func_ptr)(int); - fp = (func_ptr)[](int x) { return x + 1; }; - - int (^bp)(int) = [](int x) { return x + 1; }; - bp = [](int x) { return x + 1; }; - - typedef int (^block_ptr)(int); - bp = (block_ptr)[](int x) { return x + 1; }; - } - - int &accept_lambda_conv(int (*fp)(int)); - float &accept_lambda_conv(int (^bp)(int)); - - void call_with_lambda() { - int &ir = accept_lambda_conv([](int x) { return x + 1; }); - } - - template<typename T> using id = T; - - auto a = [](){}; - struct C : decltype(a) { - using decltype(a)::operator id<void(*)()>; - private: - using decltype(a)::operator id<void(^)()>; - } extern c; - - struct D : decltype(a) { - using decltype(a)::operator id<void(^)()>; - private: - using decltype(a)::operator id<void(*)()>; // expected-note {{here}} - } extern d; - - bool r1 = c; - bool r2 = d; // expected-error {{private}} -} - -namespace PR13117 { - struct A { - template<typename ... Args> static void f(Args...); - - template<typename ... Args> static void f1() - { - (void)^(Args args) { // expected-error{{block contains unexpanded parameter pack 'Args'}} - }; - } - - template<typename ... Args> static void f2() - { - // FIXME: Allow this. - f( - ^(Args args) // expected-error{{block contains unexpanded parameter pack 'Args'}} - { } - ... // expected-error{{pack expansion does not contain any unexpanded parameter packs}} - ); - } - - template<typename ... Args> static void f3() - { - (void)[](Args args) { // expected-error{{expression contains unexpanded parameter pack 'Args'}} - }; - } - - template<typename ... Args> static void f4() - { - f([](Args args) { } ...); - } - }; - - void g() { - A::f1<int, int>(); - A::f2<int, int>(); - } -} diff --git a/test/CXX/expr/expr.prim/expr.prim.lambda/default-arguments.cpp b/test/CXX/expr/expr.prim/expr.prim.lambda/default-arguments.cpp deleted file mode 100644 index 9b0a9ad8c2573..0000000000000 --- a/test/CXX/expr/expr.prim/expr.prim.lambda/default-arguments.cpp +++ /dev/null @@ -1,53 +0,0 @@ -// RUN: %clang_cc1 -fsyntax-only -std=c++11 %s -verify - -void defargs() { - auto l1 = [](int i, int j = 17, int k = 18) { return i + j + k; }; - int i1 = l1(1); - int i2 = l1(1, 2); - int i3 = l1(1, 2, 3); -} - - -void defargs_errors() { - auto l1 = [](int i, - int j = 17, - int k) { }; // expected-error{{missing default argument on parameter 'k'}} - - auto l2 = [](int i, int j = i) {}; // expected-error{{default argument references parameter 'i'}} - - int foo; - auto l3 = [](int i = foo) {}; // expected-error{{default argument references local variable 'foo' of enclosing function}} -} - -struct NonPOD { - NonPOD(); - NonPOD(const NonPOD&); - ~NonPOD(); -}; - -struct NoDefaultCtor { - NoDefaultCtor(const NoDefaultCtor&); // expected-note{{candidate constructor}} \ - // expected-note{{candidate constructor not viable: requires 1 argument, but 0 were provided}} - ~NoDefaultCtor(); -}; - -template<typename T> -void defargs_in_template_unused(T t) { - auto l1 = [](const T& value = T()) { }; // expected-error{{no matching constructor for initialization of 'NoDefaultCtor'}} - l1(t); -} - -template void defargs_in_template_unused(NonPOD); -template void defargs_in_template_unused(NoDefaultCtor); // expected-note{{in instantiation of function template specialization 'defargs_in_template_unused<NoDefaultCtor>' requested here}} - -template<typename T> -void defargs_in_template_used() { - auto l1 = [](const T& value = T()) { }; // expected-error{{no matching constructor for initialization of 'NoDefaultCtor'}} \ - // expected-note{{candidate function not viable: requires single argument 'value', but no arguments were provided}} \ - // expected-note{{conversion candidate of type 'void (*)(const NoDefaultCtor &)'}} - l1(); // expected-error{{no matching function for call to object of type '(lambda at }} -} - -template void defargs_in_template_used<NonPOD>(); -template void defargs_in_template_used<NoDefaultCtor>(); // expected-note{{in instantiation of function template specialization}} - diff --git a/test/CXX/expr/expr.prim/expr.prim.lambda/p10.cpp b/test/CXX/expr/expr.prim/expr.prim.lambda/p10.cpp deleted file mode 100644 index 245e27042be35..0000000000000 --- a/test/CXX/expr/expr.prim/expr.prim.lambda/p10.cpp +++ /dev/null @@ -1,40 +0,0 @@ -// RUN: %clang_cc1 -std=c++11 %s -verify - -int GlobalVar; // expected-note {{declared here}} - -namespace N { - int AmbiguousVar; // expected-note {{candidate}} -} -int AmbiguousVar; // expected-note {{candidate}} -using namespace N; - -class X0 { - int Member; - - static void Overload(int); - void Overload(); - virtual X0& Overload(float); - - void explicit_capture() { - int variable; // expected-note {{declared here}} - (void)[&Overload] () {}; // expected-error {{does not name a variable}} - (void)[&GlobalVar] () {}; // expected-error {{does not have automatic storage duration}} - (void)[&AmbiguousVar] () {}; // expected-error {{reference to 'AmbiguousVar' is ambiguous}} - (void)[&Variable] () {}; // expected-error {{use of undeclared identifier 'Variable'; did you mean 'variable'}} - } -}; - -void test_reaching_scope() { - int local; // expected-note{{declared here}} - static int local_static; // expected-note{{'local_static' declared here}} - (void)[=]() { - struct InnerLocal { - void member() { - (void)[local, // expected-error{{reference to local variable 'local' declared in enclosing function 'test_reaching_scope'}} - local_static]() { // expected-error{{'local_static' cannot be captured because it does not have automatic storage duration}} - return 0; - }; - } - }; - }; -} diff --git a/test/CXX/expr/expr.prim/expr.prim.lambda/p11-1y.cpp b/test/CXX/expr/expr.prim/expr.prim.lambda/p11-1y.cpp deleted file mode 100644 index 63e51a7614490..0000000000000 --- a/test/CXX/expr/expr.prim/expr.prim.lambda/p11-1y.cpp +++ /dev/null @@ -1,78 +0,0 @@ -// RUN: %clang_cc1 -std=c++1y %s -verify - -const char *has_no_member = [x("hello")] {}.x; // expected-error {{no member named 'x'}} - -double f; -auto with_float = [f(1.0f)] { - using T = decltype(f); - using T = float; -}; -auto with_float_2 = [&f(f)] { // ok, refers to outer f - using T = decltype(f); - using T = double&; -}; - -// Within the lambda-expression's compound-statement, -// the identifier in the init-capture hides any declaration -// of the same name in scopes enclosing the lambda-expression. -void hiding() { - char c; - (void) [c("foo")] { - static_assert(sizeof(c) == sizeof(const char*), ""); - }; - (void) [c("bar")] () -> decltype(c) { // outer c, not init-capture - return "baz"; // expected-error {{cannot initialize}} - }; -} - -struct ExplicitCopy { - ExplicitCopy(); // expected-note 2{{not viable}} - explicit ExplicitCopy(const ExplicitCopy&); -}; -auto init_kind_1 = [ec(ExplicitCopy())] {}; -auto init_kind_2 = [ec = ExplicitCopy()] {}; // expected-error {{no matching constructor}} - -template<typename T> void init_kind_template() { - auto init_kind_1 = [ec(T())] {}; - auto init_kind_2 = [ec = T()] {}; // expected-error {{no matching constructor}} -} -template void init_kind_template<int>(); -template void init_kind_template<ExplicitCopy>(); // expected-note {{instantiation of}} - -void void_fn(); -int overload_fn(); -int overload_fn(int); - -auto bad_init_1 = [a()] {}; // expected-error {{expected expression}} -auto bad_init_2 = [a(1, 2)] {}; // expected-error {{initializer for lambda capture 'a' contains multiple expressions}} -auto bad_init_3 = [&a(void_fn())] {}; // expected-error {{cannot form a reference to 'void'}} -auto bad_init_4 = [a(void_fn())] {}; // expected-error {{has incomplete type 'void'}} -auto bad_init_5 = [a(overload_fn)] {}; // expected-error {{cannot deduce type for lambda capture 'a' from initializer of type '<overloaded function}} -auto bad_init_6 = [a{overload_fn}] {}; // expected-error {{cannot deduce type for lambda capture 'a' from initializer list}} -auto bad_init_7 = [a{{1}}] {}; // expected-error {{cannot deduce type for lambda capture 'a' from nested initializer list}} - -template<typename...T> void pack_1(T...t) { (void)[a(t...)] {}; } // expected-error {{initializer missing for lambda capture 'a'}} -template void pack_1<>(); // expected-note {{instantiation of}} - -// FIXME: Might need lifetime extension for the temporary here. -// See DR1695. -auto a = [a(4), b = 5, &c = static_cast<const int&&>(0)] { - static_assert(sizeof(a) == sizeof(int), ""); - static_assert(sizeof(b) == sizeof(int), ""); - using T = decltype(c); - using T = const int &; -}; -auto b = [a{0}] {}; // OK, per N3922 - -struct S { S(); S(S&&); }; -template<typename T> struct remove_reference { typedef T type; }; -template<typename T> struct remove_reference<T&> { typedef T type; }; -template<typename T> decltype(auto) move(T &&t) { return static_cast<typename remove_reference<T>::type&&>(t); } -auto s = [s(move(S()))] {}; - -template<typename T> T instantiate_test(T t) { - [x(&t)]() { *x = 1; } (); // expected-error {{assigning to 'const char *'}} - return t; -} -int instantiate_test_1 = instantiate_test(0); -const char *instantiate_test_2 = instantiate_test("foo"); // expected-note {{here}} diff --git a/test/CXX/expr/expr.prim/expr.prim.lambda/p11.cpp b/test/CXX/expr/expr.prim/expr.prim.lambda/p11.cpp deleted file mode 100644 index d265dd757398e..0000000000000 --- a/test/CXX/expr/expr.prim/expr.prim.lambda/p11.cpp +++ /dev/null @@ -1,16 +0,0 @@ -// RUN: %clang_cc1 -std=c++11 %s -verify - -void test_reaching_scope() { - int local; // expected-note{{declared here}} - static int local_static; - (void)[=]() { - struct InnerLocal { - void member() { - (void)[=]() { - return local + // expected-error{{reference to local variable 'local' declared in enclosing function 'test_reaching_scope'}} - local_static; - }; - } - }; - }; -} diff --git a/test/CXX/expr/expr.prim/expr.prim.lambda/p12.cpp b/test/CXX/expr/expr.prim/expr.prim.lambda/p12.cpp deleted file mode 100644 index e7fce11abc5e3..0000000000000 --- a/test/CXX/expr/expr.prim/expr.prim.lambda/p12.cpp +++ /dev/null @@ -1,77 +0,0 @@ -// RUN: %clang_cc1 -std=c++11 %s -Wunused -Wno-unused-lambda-capture -verify - -void odr_used() { - int i = 17; - [i]{}(); -} - -struct ReachingThis { - static void static_foo() { - (void)[this](){}; // expected-error{{'this' cannot be captured in this context}} - - struct Local { - int i; - - void bar() { - (void)[this](){}; - (void)[&](){i = 7; }; - } - }; - } - - void foo() { - (void)[this](){}; - - struct Local { - int i; - - static void static_bar() { - (void)[this](){}; // expected-error{{'this' cannot be captured in this context}} - (void)[&](){i = 7; }; // expected-error{{invalid use of member 'i' in static member function}} - } - }; - } -}; - -void immediately_enclosing(int i) { // expected-note{{'i' declared here}} - [i]() { - [i] {}(); - }(); - - [=]() { - [i] {}(); - }(); - - []() { // expected-note{{lambda expression begins here}} - [i] {}(); // expected-error{{variable 'i' cannot be implicitly captured in a lambda with no capture-default specified}} - }(); -} - -void f1(int i) { // expected-note{{declared here}} - int const N = 20; - auto m1 = [=]{ - int const M = 30; - auto m2 = [i]{ - int x[N][M]; - x[0][0] = i; - }; - (void)N; - (void)M; - (void)m2; - }; - struct s1 { - int f; - void work(int n) { // expected-note{{declared here}} - int m = n*n; - int j = 40; // expected-note{{declared here}} - auto m3 = [this,m] { // expected-note 3{{lambda expression begins here}} - auto m4 = [&,j] { // expected-error{{variable 'j' cannot be implicitly captured in a lambda with no capture-default specified}} - int x = n; // expected-error{{variable 'n' cannot be implicitly captured in a lambda with no capture-default specified}} - x += m; - x += i; // expected-error{{variable 'i' cannot be implicitly captured in a lambda with no capture-default specified}} - x += f; - }; - }; - } - }; -} diff --git a/test/CXX/expr/expr.prim/expr.prim.lambda/p13.cpp b/test/CXX/expr/expr.prim/expr.prim.lambda/p13.cpp deleted file mode 100644 index b55beb7d4ed78..0000000000000 --- a/test/CXX/expr/expr.prim/expr.prim.lambda/p13.cpp +++ /dev/null @@ -1,16 +0,0 @@ -// RUN: %clang_cc1 -std=c++11 %s -Wunused -Wno-unused-lambda-capture -verify - -void f2() { - int i = 1; - void g1(int = ([i]{ return i; })()); // expected-error{{lambda expression in default argument cannot capture any entity}} - void g2(int = ([i]{ return 0; })()); // expected-error{{lambda expression in default argument cannot capture any entity}} - void g3(int = ([=]{ return i; })()); // expected-error{{lambda expression in default argument cannot capture any entity}} - void g4(int = ([=]{ return 0; })()); - void g5(int = ([]{ return sizeof i; })()); -} - -namespace lambda_in_default_args { - int f(int = [] () -> int { int n; return ++n; } ()); - template<typename T> T g(T = [] () -> T { T n; return ++n; } ()); - int k = f() + g<int>(); -} diff --git a/test/CXX/expr/expr.prim/expr.prim.lambda/p14.cpp b/test/CXX/expr/expr.prim/expr.prim.lambda/p14.cpp deleted file mode 100644 index 7fc86e8109270..0000000000000 --- a/test/CXX/expr/expr.prim/expr.prim.lambda/p14.cpp +++ /dev/null @@ -1,111 +0,0 @@ -// RUN: %clang_cc1 -fsyntax-only -std=c++11 %s -verify - -template<typename T> void capture(const T&); - -class NonCopyable { - NonCopyable(const NonCopyable&); // expected-note 2 {{implicitly declared private here}} -public: - void foo() const; -}; - -class NonConstCopy { -public: - NonConstCopy(NonConstCopy&); // expected-note{{would lose const}} -}; - -void capture_by_copy(NonCopyable nc, NonCopyable &ncr, const NonConstCopy nco) { - (void)[nc] { }; // expected-error{{capture of variable 'nc' as type 'NonCopyable' calls private copy constructor}} - (void)[=] { // expected-error{{capture of variable 'ncr' as type 'NonCopyable' calls private copy constructor}} - ncr.foo(); - }(); - - [nco] {}(); // expected-error{{no matching constructor for initialization of 'const NonConstCopy'}} -} - -struct NonTrivial { - NonTrivial(); - NonTrivial(const NonTrivial &); - ~NonTrivial(); -}; - -struct CopyCtorDefault { - CopyCtorDefault(); - CopyCtorDefault(const CopyCtorDefault&, NonTrivial nt = NonTrivial()); - - void foo() const; -}; - -void capture_with_default_args(CopyCtorDefault cct) { - (void)[=] () -> void { cct.foo(); }; -} - -struct ExpectedArrayLayout { - CopyCtorDefault array[3]; -}; - -void capture_array() { - CopyCtorDefault array[3]; - auto x = [=]() -> void { - capture(array[0]); - }; - static_assert(sizeof(x) == sizeof(ExpectedArrayLayout), "layout mismatch"); -} - -// Check for the expected non-static data members. - -struct ExpectedLayout { - char a; - short b; -}; - -void test_layout(char a, short b) { - auto x = [=] () -> void { - capture(a); - capture(b); - }; - static_assert(sizeof(x) == sizeof(ExpectedLayout), "Layout mismatch!"); -} - -struct ExpectedThisLayout { - ExpectedThisLayout* a; - void f() { - auto x = [this]() -> void {}; - static_assert(sizeof(x) == sizeof(ExpectedThisLayout), "Layout mismatch!"); - } -}; - -struct CaptureArrayAndThis { - int value; - - void f() { - int array[3]; - [=]() -> int { - int result = value; - for (unsigned i = 0; i < 3; ++i) - result += array[i]; - return result; - }(); - } -}; - -namespace rdar14468891 { - class X { - public: - virtual ~X() = 0; // expected-note{{unimplemented pure virtual method '~X' in 'X'}} - }; - - class Y : public X { }; - - void capture(X &x) { - [x]() {}(); // expected-error{{by-copy capture of value of abstract type 'rdar14468891::X'}} - } -} - -namespace rdar15560464 { - struct X; // expected-note{{forward declaration of 'rdar15560464::X'}} - void foo(const X& param) { - auto x = ([=]() { - auto& y = param; // expected-error{{by-copy capture of variable 'param' with incomplete type 'const rdar15560464::X'}} - }); - } -} diff --git a/test/CXX/expr/expr.prim/expr.prim.lambda/p15-star-this-capture.cpp b/test/CXX/expr/expr.prim/expr.prim.lambda/p15-star-this-capture.cpp deleted file mode 100644 index bae1e25add352..0000000000000 --- a/test/CXX/expr/expr.prim/expr.prim.lambda/p15-star-this-capture.cpp +++ /dev/null @@ -1,22 +0,0 @@ -// RUN: %clang_cc1 -fsyntax-only -std=c++1z %s -verify
-
-class NonCopyable {
- NonCopyable(const NonCopyable&) = delete; //expected-note3{{explicitly marked deleted here}}
- int x = 10;
- void foo() {
- auto L = [this] { return x; };
- const auto &M = [*this] { return x; };//expected-error{{call to deleted}}
- const auto &M2 = [this] () -> auto&& {
- ++x;
- return [*this] { //expected-error{{call to deleted}} expected-warning{{reference to local}}
- return ++x; //expected-error{{read-only}}
- };
- };
- const auto &M3 = [*this] () mutable -> auto&& { //expected-error{{call to deleted}}
- ++x;
- return [this] { // expected-warning{{reference to local}}
- return x;
- };
- };
- }
-};
diff --git a/test/CXX/expr/expr.prim/expr.prim.lambda/p15.cpp b/test/CXX/expr/expr.prim/expr.prim.lambda/p15.cpp deleted file mode 100644 index b4b1605ab0025..0000000000000 --- a/test/CXX/expr/expr.prim/expr.prim.lambda/p15.cpp +++ /dev/null @@ -1,13 +0,0 @@ -// RUN: %clang_cc1 -fsyntax-only -std=c++11 %s -verify -// expected-no-diagnostics - -class NonCopyable { - NonCopyable(const NonCopyable&); -}; - -void capture_by_ref(NonCopyable nc, NonCopyable &ncr) { - int array[3]; - (void)[&nc] () -> void {}; - (void)[&ncr] () -> void {}; - (void)[&array] () -> void {}; -} diff --git a/test/CXX/expr/expr.prim/expr.prim.lambda/p16.cpp b/test/CXX/expr/expr.prim/expr.prim.lambda/p16.cpp deleted file mode 100644 index 905192ff830b8..0000000000000 --- a/test/CXX/expr/expr.prim/expr.prim.lambda/p16.cpp +++ /dev/null @@ -1,40 +0,0 @@ -// RUN: %clang_cc1 -std=c++11 %s -Wunused -Wno-unused-lambda-capture -verify - - -struct X { - X(const X&) = delete; // expected-note 2{{explicitly marked deleted}} - X(X&); -}; - -void test_capture(X x) { - [x] { }(); // okay: non-const copy ctor - - [x] { - [x] { // expected-error{{call to deleted constructor of 'X'}} - }(); - }(); - - [x] { - [&x] { - [x] { // expected-error{{call to deleted constructor of 'const X'}} - }(); - }(); - }(); - - int a; - [=]{ - [&] { - int &x = a; // expected-error{{binding value of type 'const int' to reference to type 'int' drops 'const' qualifier}} - int &x2 = a; // expected-error{{binding value of type 'const int' to reference to type 'int' drops 'const' qualifier}} - }(); - }(); - - [=]{ - [&a] { - [&] { - int &x = a; // expected-error{{binding value of type 'const int' to reference to type 'int' drops 'const' qualifier}} - int &x2 = a; // expected-error{{binding value of type 'const int' to reference to type 'int' drops 'const' qualifier}} - }(); - }(); - }(); -} diff --git a/test/CXX/expr/expr.prim/expr.prim.lambda/p18.cpp b/test/CXX/expr/expr.prim/expr.prim.lambda/p18.cpp deleted file mode 100644 index 72cf93be5190f..0000000000000 --- a/test/CXX/expr/expr.prim/expr.prim.lambda/p18.cpp +++ /dev/null @@ -1,46 +0,0 @@ -// RUN: %clang_cc1 -std=c++11 %s -Wunused -Wno-unused-lambda-capture -verify -// expected-no-diagnostics - -template<typename T, typename U> -struct is_same { - static const bool value = false; -}; - -template<typename T> -struct is_same<T, T> { - static const bool value = true; -}; - -void f3() { - float x, &r = x; - int i; - int &ir = i; - const int &irc = i; - - [=,&irc,&ir] { - static_assert(is_same<decltype(((r))), float const&>::value, - "should be const float&"); - static_assert(is_same<decltype(x), float>::value, "should be float"); - static_assert(is_same<decltype((x)), const float&>::value, - "should be const float&"); - static_assert(is_same<decltype(r), float&>::value, "should be float&"); - static_assert(is_same<decltype(ir), int&>::value, "should be int&"); - static_assert(is_same<decltype((ir)), int&>::value, "should be int&"); - static_assert(is_same<decltype(irc), const int&>::value, - "should be const int&"); - static_assert(is_same<decltype((irc)), const int&>::value, - "should be const int&"); - }(); - - [=] { - [=] () mutable { - static_assert(is_same<decltype(x), float>::value, "should be float"); - static_assert(is_same<decltype((x)), float&>::value, - "should be float&"); - }(); - }(); - - [&i] { - static_assert(is_same<decltype((i)), int&>::value, "should be int&"); - }(); -} diff --git a/test/CXX/expr/expr.prim/expr.prim.lambda/p19.cpp b/test/CXX/expr/expr.prim/expr.prim.lambda/p19.cpp deleted file mode 100644 index a8b40249f0f0f..0000000000000 --- a/test/CXX/expr/expr.prim/expr.prim.lambda/p19.cpp +++ /dev/null @@ -1,28 +0,0 @@ -// RUN: %clang_cc1 -std=c++11 %s -Wunused -Wno-unused-lambda-capture -verify - -struct MoveOnly { - MoveOnly(MoveOnly&&); - MoveOnly(const MoveOnly&); -}; - -template<typename T> T &&move(T&); -void test_special_member_functions(MoveOnly mo, int i) { - auto lambda1 = [i]() { }; // expected-note 2{{lambda expression begins here}} expected-note 2{{candidate}} - - // Default constructor - decltype(lambda1) lambda2; // expected-error{{no matching constructor}} - - // Copy assignment operator - lambda1 = lambda1; // expected-error{{copy assignment operator is implicitly deleted}} - - // Move assignment operator - lambda1 = move(lambda1); // expected-error{{copy assignment operator is implicitly deleted}} - - // Copy constructor - decltype(lambda1) lambda3 = lambda1; - decltype(lambda1) lambda4(lambda1); - - // Move constructor - decltype(lambda1) lambda5 = move(lambda1); - decltype(lambda1) lambda6(move(lambda1)); -} diff --git a/test/CXX/expr/expr.prim/expr.prim.lambda/p2-generic-lambda-1y.cpp b/test/CXX/expr/expr.prim/expr.prim.lambda/p2-generic-lambda-1y.cpp deleted file mode 100644 index d791ed60cfca4..0000000000000 --- a/test/CXX/expr/expr.prim/expr.prim.lambda/p2-generic-lambda-1y.cpp +++ /dev/null @@ -1,25 +0,0 @@ -// RUN: %clang_cc1 -fsyntax-only -verify %s -std=c++1y -DCXX1Y - -// prvalue -void prvalue() { - auto&& x = [](auto a)->void { }; - auto& y = [](auto *a)->void { }; // expected-error{{cannot bind to a temporary of type}} -} - -namespace std { - class type_info; -} - -struct P { - virtual ~P(); -}; - -void unevaluated_operand(P &p, int i) { //expected-note{{declared here}} - // FIXME: this should only emit one error. - int i2 = sizeof([](auto a, auto b)->void{}(3, '4')); // expected-error{{lambda expression in an unevaluated operand}} \ - // expected-error{{invalid application of 'sizeof'}} - const std::type_info &ti1 = typeid([](auto &a) -> P& { static P p; return p; }(i)); // expected-warning {{expression with side effects will be evaluated despite being used as an operand to 'typeid'}} - const std::type_info &ti2 = typeid([](auto) -> int { return i; }(i)); // expected-error{{lambda expression in an unevaluated operand}}\ - // expected-error{{cannot be implicitly captured}}\ - // expected-note{{begins here}} -} diff --git a/test/CXX/expr/expr.prim/expr.prim.lambda/p2-template-parameter.cpp b/test/CXX/expr/expr.prim/expr.prim.lambda/p2-template-parameter.cpp deleted file mode 100644 index f120a63badcbe..0000000000000 --- a/test/CXX/expr/expr.prim/expr.prim.lambda/p2-template-parameter.cpp +++ /dev/null @@ -1,7 +0,0 @@ -// RUN: %clang_cc1 -std=c++17 %s -verify - -template<auto> struct Nothing {}; - -void pr33696() { - Nothing<[]() { return 0; }()> nothing; // expected-error{{a lambda expression cannot appear in this context}} -} diff --git a/test/CXX/expr/expr.prim/expr.prim.lambda/p2.cpp b/test/CXX/expr/expr.prim/expr.prim.lambda/p2.cpp deleted file mode 100644 index 872248e77e6ae..0000000000000 --- a/test/CXX/expr/expr.prim/expr.prim.lambda/p2.cpp +++ /dev/null @@ -1,43 +0,0 @@ -// RUN: %clang_cc1 -fsyntax-only -std=c++11 -Wno-unused-value %s -verify - -// prvalue -void prvalue() { - auto&& x = []()->void { }; - auto& y = []()->void { }; // expected-error{{cannot bind to a temporary of type}} -} - -namespace std { - class type_info; -} - -struct P { - virtual ~P(); -}; - -void unevaluated_operand(P &p, int i) { - int i2 = sizeof([] ()->int { return 0; }()); // expected-error{{lambda expression in an unevaluated operand}} - const std::type_info &ti1 = typeid([&]() -> P& { return p; }()); - const std::type_info &ti2 = typeid([&]() -> int { return i; }()); // expected-error{{lambda expression in an unevaluated operand}} -} - -template<typename T> -struct Boom { - Boom(const Boom&) { - T* x = 1; // expected-error{{cannot initialize a variable of type 'int *' with an rvalue of type 'int'}} \ - // expected-error{{cannot initialize a variable of type 'double *' with an rvalue of type 'int'}} - } - void tickle() const; -}; - -void odr_used(P &p, Boom<int> boom_int, Boom<float> boom_float, - Boom<double> boom_double) { - const std::type_info &ti1 - = typeid([=,&p]() -> P& { boom_int.tickle(); return p; }()); // expected-note{{in instantiation of member function 'Boom<int>::Boom' requested here}} - // This does not cause the instantiation of the Boom copy constructor, - // because the copy-initialization of the capture of boom_float occurs in an - // unevaluated operand. - const std::type_info &ti2 - = typeid([=]() -> int { boom_float.tickle(); return 0; }()); // expected-error{{lambda expression in an unevaluated operand}} - - auto foo = [=]() -> int { boom_double.tickle(); return 0; }; // expected-note{{in instantiation of member function 'Boom<double>::Boom' requested here}} -} diff --git a/test/CXX/expr/expr.prim/expr.prim.lambda/p20.cpp b/test/CXX/expr/expr.prim/expr.prim.lambda/p20.cpp deleted file mode 100644 index 17eb841fc3fcf..0000000000000 --- a/test/CXX/expr/expr.prim/expr.prim.lambda/p20.cpp +++ /dev/null @@ -1,13 +0,0 @@ -// RUN: %clang_cc1 -std=c++11 %s -Wunused -verify -// expected-no-diagnostics - -template<typename T> -void destroy(T* ptr) { - ptr->~T(); - (*ptr).~T(); -} - -void destructor() { - auto lambda = []{}; - destroy(&lambda); -} diff --git a/test/CXX/expr/expr.prim/expr.prim.lambda/p21.cpp b/test/CXX/expr/expr.prim/expr.prim.lambda/p21.cpp deleted file mode 100644 index bc2c9997379a6..0000000000000 --- a/test/CXX/expr/expr.prim/expr.prim.lambda/p21.cpp +++ /dev/null @@ -1,10 +0,0 @@ -// RUN: %clang_cc1 -fsyntax-only -std=c++11 %s -verify -// expected-no-diagnostics - -struct DirectInitOnly { - explicit DirectInitOnly(DirectInitOnly&); -}; - -void direct_init_capture(DirectInitOnly &dio) { - [dio] {}(); -} diff --git a/test/CXX/expr/expr.prim/expr.prim.lambda/p23.cpp b/test/CXX/expr/expr.prim/expr.prim.lambda/p23.cpp deleted file mode 100644 index 4ae34dec3e34a..0000000000000 --- a/test/CXX/expr/expr.prim/expr.prim.lambda/p23.cpp +++ /dev/null @@ -1,81 +0,0 @@ -// RUN: %clang_cc1 -fsyntax-only -std=c++11 %s -verify -Wno-c++1y-extensions -// RUN: %clang_cc1 -fsyntax-only -std=c++1y %s -verify - -void print(); - -template<typename T, typename... Ts> -void print(T first, Ts... rest) { - (void)first; - print(rest...); -} - -template<typename... Ts> -void unexpanded_capture(Ts ...values) { - auto unexp = [values] {}; // expected-error{{initializer contains unexpanded parameter pack 'values'}} -} - -template<typename... Ts> -void implicit_capture(Ts ...values) { - auto implicit = [&] { print(values...); }; - implicit(); -} - -template<typename... Ts> -void do_print(Ts... values) { - auto bycopy = [values...]() { print(values...); }; - bycopy(); - auto byref = [&values...]() { print(values...); }; - byref(); - - auto bycopy2 = [=]() { print(values...); }; - bycopy2(); - auto byref2 = [&]() { print(values...); }; - byref2(); -} - -template void do_print(int, float, double); - -template<typename T, int... Values> -void bogus_expansions(T x) { - auto l1 = [x...] {}; // expected-error{{pack expansion does not contain any unexpanded parameter packs}} - auto l2 = [Values...] {}; // expected-error{{'Values' in capture list does not name a variable}} -} - -void g(int*, float*, double*); - -template<class... Args> -void std_example(Args... args) { - auto lm = [&, args...] { return g(args...); }; -}; - -template void std_example(int*, float*, double*); - -template<typename ...Args> -void variadic_lambda(Args... args) { - auto lambda = [](Args... inner_args) { return g(inner_args...); }; - lambda(args...); -} - -template void variadic_lambda(int*, float*, double*); - -template<typename ...Args> -void init_capture_pack_err(Args ...args) { - [as(args)...] {} (); // expected-error {{expected ','}} - [as...(args)]{} (); // expected-error {{expected ','}} -} - -template<typename ...Args> -void init_capture_pack_multi(Args ...args) { - [as(args...)] {} (); // expected-error {{initializer missing for lambda capture 'as'}} expected-error {{multiple}} -} -template void init_capture_pack_multi(); // expected-note {{instantiation}} -template void init_capture_pack_multi(int); -template void init_capture_pack_multi(int, int); // expected-note {{instantiation}} - -template<typename ...Args> -void init_capture_pack_outer(Args ...args) { - print([as(args)] { return sizeof(as); } () ...); -} -template void init_capture_pack_outer(); -template void init_capture_pack_outer(int); -template void init_capture_pack_outer(int, int); diff --git a/test/CXX/expr/expr.prim/expr.prim.lambda/p3.cpp b/test/CXX/expr/expr.prim/expr.prim.lambda/p3.cpp deleted file mode 100644 index db40bd5d1420e..0000000000000 --- a/test/CXX/expr/expr.prim/expr.prim.lambda/p3.cpp +++ /dev/null @@ -1,19 +0,0 @@ -// RUN: %clang_cc1 -fsyntax-only -std=c++11 %s -verify -// RUN: %clang_cc1 -fsyntax-only -std=c++14 %s -verify -// RUN: %clang_cc1 -fsyntax-only -std=c++17 %s -verify - -void test_nonaggregate(int i) { - auto lambda = [i]() -> void {}; // expected-note 2{{candidate constructor}} - decltype(lambda) foo = { 1 }; // expected-error{{no matching constructor}} - static_assert(__is_literal(decltype(lambda)) == (__cplusplus >= 201703L), ""); - - auto lambda2 = []{}; // expected-note 2{{candidate constructor}} - decltype(lambda2) bar = {}; // expected-error{{no matching constructor}} - static_assert(__is_literal(decltype(lambda2)) == (__cplusplus >= 201703L), ""); -} - -constexpr auto literal = []{}; -#if __cplusplus < 201703L -// expected-error@-2 {{constexpr variable cannot have non-literal type}} -// expected-note@-3 {{lambda closure types are non-literal types before C++17}} -#endif diff --git a/test/CXX/expr/expr.prim/expr.prim.lambda/p4-1y.cpp b/test/CXX/expr/expr.prim/expr.prim.lambda/p4-1y.cpp deleted file mode 100644 index f8461335b7689..0000000000000 --- a/test/CXX/expr/expr.prim/expr.prim.lambda/p4-1y.cpp +++ /dev/null @@ -1,66 +0,0 @@ -// RUN: %clang_cc1 -fsyntax-only -std=c++1y %s -verify - -int a; -int &b = [] (int &r) -> decltype(auto) { return r; } (a); -int &c = [] (int &r) -> decltype(auto) { return (r); } (a); -int &d = [] (int &r) -> auto & { return r; } (a); -int &e = [] (int &r) -> auto { return r; } (a); // expected-error {{cannot bind to a temporary}} -int &f = [] (int r) -> decltype(auto) { return r; } (a); // expected-error {{cannot bind to a temporary}} -int &g = [] (int r) -> decltype(auto) { return (r); } (a); // expected-warning {{reference to stack}} - - -int test_explicit_auto_return() -{ - struct X {}; - auto L = [](auto F, auto a) { return F(a); }; - auto M = [](auto a) -> auto { return a; }; // OK - auto MRef = [](auto b) -> auto& { return b; }; //expected-warning{{reference to stack}} - auto MPtr = [](auto c) -> auto* { return &c; }; //expected-warning{{address of stack}} - auto MDeclType = [](auto&& d) -> decltype(auto) { return static_cast<decltype(d)>(d); }; //OK - M(3); - - auto &&x = MDeclType(X{}); - auto &&x1 = M(X{}); - auto &&x2 = MRef(X{});//expected-note{{in instantiation of}} - auto &&x3 = MPtr(X{}); //expected-note{{in instantiation of}} - return 0; -} - -int test_implicit_auto_return() -{ - { - auto M = [](auto a) { return a; }; - struct X {}; - X x = M(X{}); - - } -} - -int test_multiple_returns() { - auto M = [](auto a) { - bool k; - if (k) - return a; - else - return 5; //expected-error{{deduced as 'int' here}} - }; - M(3); // OK - M('a'); //expected-note{{in instantiation of}} - return 0; -} -int test_no_parameter_list() -{ - static int si = 0; - auto M = [] { return 5; }; // OK - auto M2 = [] -> auto&& { return si; }; // expected-error{{lambda requires '()'}} - M(); -} - -int test_conditional_in_return() { - auto Fac = [](auto f, auto n) { - return n <= 0 ? n : f(f, n - 1) * n; - }; - // FIXME: this test causes a recursive limit - need to error more gracefully. - //Fac(Fac, 3); - -}
\ No newline at end of file diff --git a/test/CXX/expr/expr.prim/expr.prim.lambda/p4.cpp b/test/CXX/expr/expr.prim/expr.prim.lambda/p4.cpp deleted file mode 100644 index a36175af6fec5..0000000000000 --- a/test/CXX/expr/expr.prim/expr.prim.lambda/p4.cpp +++ /dev/null @@ -1,52 +0,0 @@ -// RUN: %clang_cc1 -fsyntax-only -std=c++11 %s -verify -// RUN: %clang_cc1 -fsyntax-only -std=c++1y %s -verify -DCPP1Y - -void missing_lambda_declarator() { - [](){}(); -} - -template<typename T> T get(); - -void infer_void_return_type(int i) { - if (i > 17) - return []() { }(); - - if (i > 11) - return []() { return; }(); - - return [](int x) { - switch (x) { - case 0: return get<void>(); - case 1: return; - case 2: return { 1, 2.0 }; //expected-error{{cannot deduce}} - } - }(7); -} - -struct X { }; - -X infer_X_return_type(X x) { - return [&x](int y) { - if (y > 0) - return X(); - else - return x; - }(5); -} - -X infer_X_return_type_2(X x) { - return [x](int y) { - if (y > 0) - return X(); - else - return x; // ok even in c++11, per dr1048. - }(5); -} - -struct Incomplete; // expected-note{{forward declaration of 'Incomplete'}} -void test_result_type(int N) { - auto l1 = [] () -> Incomplete { }; // expected-error{{incomplete result type 'Incomplete' in lambda expression}} - - typedef int vla[N]; - auto l2 = [] () -> vla { }; // expected-error{{function cannot return array type 'vla' (aka 'int [N]')}} -} diff --git a/test/CXX/expr/expr.prim/expr.prim.lambda/p4.mm b/test/CXX/expr/expr.prim/expr.prim.lambda/p4.mm deleted file mode 100644 index 92c62904d57b2..0000000000000 --- a/test/CXX/expr/expr.prim/expr.prim.lambda/p4.mm +++ /dev/null @@ -1,8 +0,0 @@ -// RUN: %clang_cc1 -fsyntax-only -std=c++11 %s -verify - -@interface A -@end - -void test_result_type() { - auto l1 = [] () -> A { }; // expected-error{{interface type 'A' cannot be returned by value; did you forget * in 'A'?}} -} diff --git a/test/CXX/expr/expr.prim/expr.prim.lambda/p5-generic-lambda-1y.cpp b/test/CXX/expr/expr.prim/expr.prim.lambda/p5-generic-lambda-1y.cpp deleted file mode 100644 index 415c3d84560ef..0000000000000 --- a/test/CXX/expr/expr.prim/expr.prim.lambda/p5-generic-lambda-1y.cpp +++ /dev/null @@ -1,131 +0,0 @@ -// RUN: %clang_cc1 -fsyntax-only -verify %s -std=c++1y -DCXX1Y - -namespace test_factorial { - -auto Fact = [](auto Self, unsigned n) -> unsigned { - return !n ? 1 : Self(Self, n - 1) * n; -}; - -auto six = Fact(Fact, 3); - -} - -namespace overload_generic_lambda { - template <class F1, class F2> struct overload : F1, F2 { - using F1::operator(); - using F2::operator(); - overload(F1 f1, F2 f2) : F1(f1), F2(f2) { } - }; - - auto NumParams = [](auto Self, auto h, auto ... rest) -> unsigned { - return 1 + Self(Self, rest...); - }; - auto Base = [](auto Self, auto h) -> unsigned { - return 1; - }; - overload<decltype(Base), decltype(NumParams)> O(Base, NumParams); - int num_params = O(O, 5, 3, "abc", 3.14, 'a'); -} - - -namespace overload_generic_lambda_return_type_deduction { - template <class F1, class F2> struct overload : F1, F2 { - using F1::operator(); - using F2::operator(); - overload(F1 f1, F2 f2) : F1(f1), F2(f2) { } - }; - - auto NumParams = [](auto Self, auto h, auto ... rest) { - return 1 + Self(Self, rest...); - }; - auto Base = [](auto Self, auto h) { - return 1; - }; - overload<decltype(Base), decltype(NumParams)> O(Base, NumParams); - int num_params = O(O, 5, 3, "abc", 3.14, 'a'); -} - -namespace test_standard_p5 { -// FIXME: This test should eventually compile without an explicit trailing return type -auto glambda = [](auto a, auto&& b) ->bool { return a < b; }; -bool b = glambda(3, 3.14); // OK - -} -namespace test_deduction_failure { - int test() { - auto g = [](auto *a) { //expected-note{{candidate template ignored}} - return a; - }; - struct X { }; - X *x; - g(x); - g(3); //expected-error{{no matching function}} - return 0; - } - -} - -namespace test_instantiation_or_sfinae_failure { -int test2() { - { - auto L = [](auto *a) { - return (*a)(a); }; //expected-error{{called object type 'double' is not a function}} - double d; - L(&d); //expected-note{{in instantiation of}} - auto M = [](auto b) { return b; }; - L(&M); // ok - } - { - auto L = [](auto *a) ->decltype (a->foo()) { //expected-note2{{candidate template ignored:}} - return (*a)(a); }; - double d; - L(&d); //expected-error{{no matching function for call}} - auto M = [](auto b) { return b; }; - L(&M); //expected-error{{no matching function for call}} - - } - return 0; -} - - -} - -namespace test_misc { -auto GL = [](auto a, decltype(a) b) //expected-note{{candidate function}} - -> int { return a + b; }; - -void test() { - struct X { }; - GL(3, X{}); //expected-error{{no matching function}} -} - -void test2() { - auto l = [](auto *a) -> int { - (*a)(a); return 0; }; //expected-error{{called object type 'double' is not a function}} - l(&l); - double d; - l(&d); //expected-note{{in instantiation of}} -} - -} - -namespace nested_lambdas { - int test() { - auto L = [](auto a) { - return [=](auto b) { - return a + b; - }; - }; - } - auto get_lambda() { - return [](auto a) { - return a; - }; - }; - - int test2() { - auto L = get_lambda(); - L(3); - } -} - diff --git a/test/CXX/expr/expr.prim/expr.prim.lambda/p5.cpp b/test/CXX/expr/expr.prim/expr.prim.lambda/p5.cpp deleted file mode 100644 index b8504d4906500..0000000000000 --- a/test/CXX/expr/expr.prim/expr.prim.lambda/p5.cpp +++ /dev/null @@ -1,63 +0,0 @@ -// RUN: %clang_cc1 -std=c++11 %s -Winvalid-noreturn -verify - -// An attribute-specifier-seq in a lambda-declarator appertains to the -// type of the corresponding function call operator. -void test_attributes() { - auto nrl = [](int x) -> int { if (x > 0) return x; }; // expected-warning{{control may reach end of non-void lambda}} - - // FIXME: GCC accepts the [[gnu::noreturn]] attribute here. - auto nrl2 = []() [[gnu::noreturn]] { return; }; // expected-warning{{attribute 'noreturn' ignored}} -} - -template<typename T> -struct bogus_override_if_virtual : public T { - bogus_override_if_virtual() : T(*(T*)0) { } // expected-warning {{binding dereferenced null pointer to reference has undefined behavior}} - int operator()() const; -}; - -void test_quals() { - // This function call operator is declared const (9.3.1) if and only - // if the lambda- expression's parameter-declaration-clause is not - // followed by mutable. - auto l = [=](){}; // expected-note{{method is not marked volatile}} - const decltype(l) lc = l; - l(); - lc(); - - auto ml = [=]() mutable{}; // expected-note{{method is not marked const}} \ - // expected-note{{method is not marked volatile}} - const decltype(ml) mlc = ml; - ml(); - mlc(); // expected-error{{no matching function for call to object of type}} - - // It is neither virtual nor declared volatile. - volatile decltype(l) lv = l; - volatile decltype(ml) mlv = ml; - lv(); // expected-error{{no matching function for call to object of type}} - mlv(); // expected-error{{no matching function for call to object of type}} - - bogus_override_if_virtual<decltype(l)> bogus; // expected-note{{in instantiation of member function 'bogus_override_if_virtual<(lambda}} -} - -// Core issue 974: default arguments (8.3.6) may be specified in the -// parameter-declaration-clause of a lambda-declarator. -int test_default_args() { - return [](int i = 5, int j = 17) { return i+j;}(5, 6); -} - -// Any exception-specification specified on a lambda-expression -// applies to the corresponding function call operator. -void test_exception_spec() { - auto tl1 = []() throw(int) {}; - auto tl2 = []() {}; - static_assert(!noexcept(tl1()), "lambda can throw"); - static_assert(!noexcept(tl2()), "lambda can throw"); - - auto ntl1 = []() throw() {}; - auto ntl2 = []() noexcept(true) {}; - auto ntl3 = []() noexcept {}; - static_assert(noexcept(ntl1()), "lambda cannot throw"); - static_assert(noexcept(ntl2()), "lambda cannot throw"); - static_assert(noexcept(ntl3()), "lambda cannot throw"); -} - diff --git a/test/CXX/expr/expr.prim/expr.prim.lambda/p6.cpp b/test/CXX/expr/expr.prim/expr.prim.lambda/p6.cpp deleted file mode 100644 index 90a3aec50cb38..0000000000000 --- a/test/CXX/expr/expr.prim/expr.prim.lambda/p6.cpp +++ /dev/null @@ -1,32 +0,0 @@ -// RUN: %clang_cc1 -fsyntax-only -std=c++11 %s -verify -// RUN: %clang_cc1 -fsyntax-only -std=c++1z %s -verify - -void test_conversion() { - int (*fp1)(int) = [](int x) { return x + 1; }; - void (*fp2)(int) = [](int x) { }; - - const auto lambda = [](int x) { }; - void (*fp3)(int) = lambda; - - volatile const auto lambda2 = [](int x) { }; // expected-note{{but method is not marked volatile}} - void (*fp4)(int) = lambda2; // expected-error{{no viable conversion}} - - void (*fp5)(int) noexcept = [](int x) { }; -#if __cplusplus > 201402L - // expected-error@-2 {{no viable}} expected-note@-2 {{candidate}} - void (*fp5a)(int) noexcept = [](auto x) { }; - // expected-error@-1 {{no viable}} expected-note@-1 {{candidate}} - void (*fp5b)(int) noexcept = [](auto x) noexcept { }; -#endif - void (*fp6)(int) noexcept = [](int x) noexcept { }; -} - -void test_no_conversion() { - int (*fp1)(int) = [=](int x) { return x + 1; }; // expected-error{{no viable conversion}} - void (*fp2)(int) = [&](int x) { }; // expected-error{{no viable conversion}} -} - -void test_wonky() { - const auto l = [](int x) mutable -> int { return + 1; }; - l(17); // okay: uses conversion function -} diff --git a/test/CXX/expr/expr.prim/expr.prim.lambda/p7.cpp b/test/CXX/expr/expr.prim/expr.prim.lambda/p7.cpp deleted file mode 100644 index 9dbe2e189f4af..0000000000000 --- a/test/CXX/expr/expr.prim/expr.prim.lambda/p7.cpp +++ /dev/null @@ -1,56 +0,0 @@ -// RUN: %clang_cc1 -fsyntax-only -std=c++11 %s -verify - -// Check that analysis-based warnings work in lambda bodies. -void analysis_based_warnings() { - (void)[]() -> int { }; // expected-warning{{control reaches end of non-void lambda}} -} - -// Check that we get the right types of captured variables (the -// semantic-analysis part of p7). -int &check_const_int(int&); -float &check_const_int(const int&); - -void test_capture_constness(int i, const int ic) { - (void)[i,ic] ()->void { - float &fr1 = check_const_int(i); - float &fr2 = check_const_int(ic); - }; - - (void)[=] ()->void { - float &fr1 = check_const_int(i); - float &fr2 = check_const_int(ic); - }; - - (void)[i,ic] () mutable ->void { - int &ir = check_const_int(i); - float &fr = check_const_int(ic); - }; - - (void)[=] () mutable ->void { - int &ir = check_const_int(i); - float &fr = check_const_int(ic); - }; - - (void)[&i,&ic] ()->void { - int &ir = check_const_int(i); - float &fr = check_const_int(ic); - }; - - (void)[&] ()->void { - int &ir = check_const_int(i); - float &fr = check_const_int(ic); - }; -} - - -struct S1 { - int x, y; - S1 &operator=(int*); - int operator()(int); - void f() { - [&]()->int { - S1 &s1 = operator=(&this->x); - return operator()(this->x + y); - }(); - } -}; diff --git a/test/CXX/expr/expr.prim/expr.prim.lambda/p8.cpp b/test/CXX/expr/expr.prim/expr.prim.lambda/p8.cpp deleted file mode 100644 index 1cc1fd974ca5d..0000000000000 --- a/test/CXX/expr/expr.prim/expr.prim.lambda/p8.cpp +++ /dev/null @@ -1,32 +0,0 @@ -// RUN: %clang_cc1 -std=c++11 %s -verify -Wno-c++1y-extensions - -class X0 { - void explicit_capture() { - int foo; - - (void)[foo, foo] () {}; // expected-error {{'foo' can appear only once}} - (void)[this, this] () {}; // expected-error {{'this' can appear only once}} - (void)[=, foo] () {}; // expected-error {{'&' must precede a capture when}} - (void)[=, &foo] () {}; - (void)[=, this] () {}; // expected-warning {{C++2a extension}} - (void)[&, foo] () {}; - (void)[&, &foo] () {}; // expected-error {{'&' cannot precede a capture when}} - (void)[&, this] () {}; - } -}; - -struct S2 { - void f(int i); - void g(int i); -}; - -void S2::f(int i) { - (void)[&, i]{ }; - (void)[&, &i]{ }; // expected-error{{'&' cannot precede a capture when the capture default is '&'}} - (void)[=, this]{ }; // expected-warning{{C++2a extension}} - (void)[=]{ this->g(i); }; - (void)[i, i]{ }; // expected-error{{'i' can appear only once in a capture list}} - (void)[i(0), i(1)]{ }; // expected-error{{'i' can appear only once in a capture list}} - (void)[i, i(1)]{ }; // expected-error{{'i' can appear only once in a capture list}} - (void)[i(0), i]{ }; // expected-error{{'i' can appear only once in a capture list}} -} diff --git a/test/CXX/expr/expr.prim/expr.prim.lambda/templates.cpp b/test/CXX/expr/expr.prim/expr.prim.lambda/templates.cpp deleted file mode 100644 index 2bb75df7ac6aa..0000000000000 --- a/test/CXX/expr/expr.prim/expr.prim.lambda/templates.cpp +++ /dev/null @@ -1,149 +0,0 @@ -// RUN: %clang_cc1 -fsyntax-only -std=c++11 -Winvalid-noreturn %s -verify - -template<typename T> -void test_attributes() { - // FIXME: GCC accepts [[gnu::noreturn]] here. - auto nrl = []() [[gnu::noreturn]] {}; // expected-warning{{attribute 'noreturn' ignored}} -} - -template void test_attributes<int>(); - -template<typename T> -void call_with_zero() { - [](T *ptr) -> T& { return *ptr; }(0); -} - -template void call_with_zero<int>(); - -template<typename T> -T captures(T x, T y) { - auto lambda = [=, &y] () -> T { - T i = x; - return i + y; - }; - - return lambda(); -} - -struct X { - X(const X&); -}; - -X operator+(X, X); -X operator-(X, X); - -template int captures(int, int); -template X captures(X, X); - -template<typename T> -int infer_result(T x, T y) { - auto lambda = [=](bool b) { return x + y; }; - return lambda(true); // expected-error{{no viable conversion from returned value of type 'X' to function return type 'int'}} -} - -template int infer_result(int, int); -template int infer_result(X, X); // expected-note{{in instantiation of function template specialization 'infer_result<X>' requested here}} - -// Make sure that lambda's operator() can be used from templates. -template<typename F> -void accept_lambda(F f) { - f(1); -} - -template<typename T> -void pass_lambda(T x) { - accept_lambda([&x](T y) { return x + y; }); -} - -template void pass_lambda(int); - -namespace std { - class type_info; -} - -namespace p2 { - struct P { - virtual ~P(); - }; - - template<typename T> - struct Boom { - Boom(const Boom&) { - T* x = 1; // expected-error{{cannot initialize a variable of type 'float *' with an rvalue of type 'int'}} - } - void tickle() const; - }; - - template<typename R, typename T> - void odr_used(R &r, Boom<T> boom) { - const std::type_info &ti - = typeid([=,&r] () -> R& { // expected-error{{lambda expression in an unevaluated operand}} - boom.tickle(); - return r; - }()); - } - - template void odr_used(int&, Boom<int>); // expected-note{{in instantiation of function template specialization}} - - template<typename R, typename T> - void odr_used2(R &r, Boom<T> boom) { - const std::type_info &ti - = typeid([=,&r] () -> R& { // expected-note{{in instantiation of member function 'p2::Boom<float>::Boom' requested here}} - boom.tickle(); - return r; - }()); - } - - template void odr_used2(P&, Boom<float>); -} - -namespace p5 { - struct NonConstCopy { - NonConstCopy(const NonConstCopy&) = delete; - NonConstCopy(NonConstCopy&); - }; - - template<typename T> - void double_capture(T &nc) { - [=] () mutable { - [=] () mutable { - T nc2(nc); - }(); - }(); - } - - template void double_capture(NonConstCopy&); -} - -namespace NonLocalLambdaInstantation { - template<typename T> - struct X { - static int value; - }; - - template<typename T> - int X<T>::value = []{ return T(); }(); // expected-error{{cannot initialize a variable of type 'int' with an rvalue of type 'int *'}} - - template int X<int>::value; - template int X<float>::value; - template int X<int*>::value; // expected-note{{in instantiation of static data member }} - - template<typename T> - void defaults(int x = []{ return T(); }()) { }; // expected-error{{cannot initialize a parameter of type 'int' with an rvalue of type 'int *'}} \ - // expected-note{{passing argument to parameter 'x' here}} - - void call_defaults() { - defaults<int>(); - defaults<float>(); - defaults<int*>(); // expected-note{{in instantiation of default function argument expression for 'defaults<int *>' required here}} - } - - template<typename T> - struct X2 { // expected-note{{in instantiation of default member initializer 'NonLocalLambdaInstantation::X2<int *>::x'}} - int x = []{ return T(); }(); // expected-error{{cannot initialize a member subobject of type 'int' with an rvalue of type 'int *'}} - }; - - X2<int> x2i; - X2<float> x2f; - X2<int*> x2ip; // expected-note {{in evaluation of exception spec}} -} |