diff options
Diffstat (limited to 'test/CXX/expr/expr.prim/expr.prim.lambda/p4-1y.cpp')
-rw-r--r-- | test/CXX/expr/expr.prim/expr.prim.lambda/p4-1y.cpp | 66 |
1 files changed, 66 insertions, 0 deletions
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 new file mode 100644 index 0000000..f846133 --- /dev/null +++ b/test/CXX/expr/expr.prim/expr.prim.lambda/p4-1y.cpp @@ -0,0 +1,66 @@ +// 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 |