diff options
| author | Douglas Gregor <dgregor@apple.com> | 2012-02-09 18:19:44 +0000 |
|---|---|---|
| committer | Douglas Gregor <dgregor@apple.com> | 2012-02-09 18:19:44 +0000 |
| commit | a30a0bc1db19831d2e42bb3c1ddf5cfd0d94d975 (patch) | |
| tree | e1a387c573425c5dd57aaa4009ff2899618cd718 /clang/test | |
| parent | af8f33726b9a20c8f69add298fa764c27e0430b5 (diff) | |
| download | bcm5719-llvm-a30a0bc1db19831d2e42bb3c1ddf5cfd0d94d975.tar.gz bcm5719-llvm-a30a0bc1db19831d2e42bb3c1ddf5cfd0d94d975.zip | |
Tests for C++ [expr.prim.lambda]p5. We already implement all of these
semantics.
llvm-svn: 150190
Diffstat (limited to 'clang/test')
| -rw-r--r-- | clang/test/CXX/expr/expr.prim/expr.prim.lambda/p5.cpp | 60 |
1 files changed, 57 insertions, 3 deletions
diff --git a/clang/test/CXX/expr/expr.prim/expr.prim.lambda/p5.cpp b/clang/test/CXX/expr/expr.prim/expr.prim.lambda/p5.cpp index ff6e7b4438d..9df0f64ad31 100644 --- a/clang/test/CXX/expr/expr.prim/expr.prim.lambda/p5.cpp +++ b/clang/test/CXX/expr/expr.prim/expr.prim.lambda/p5.cpp @@ -1,6 +1,60 @@ -// RUN: %clang_cc1 -std=c++11 %s -verify +// 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 = []() [[noreturn]] {}; // expected-warning{{function declared 'noreturn' should not return}} +} + +template<typename T> +struct bogus_override_if_virtual : public T { + 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; +} + +// Default arguments (8.3.6) shall not be specified in the +// parameter-declaration-clause of a lambda- declarator. int test_default_args() { - (void)[](int i = 5, // expected-error{{default arguments can only be specified for parameters in a function declaration}} - int j = 17) {}; // expected-error{{default arguments can only be specified for parameters in a function declaration}} + return [](int i = 5, // expected-error{{default arguments can only be specified for parameters in a function declaration}} + int j = 17) { return i+j;}(5, 6); // expected-error{{default arguments can only be specified for parameters in a function declaration}} +} + +// 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"); } + |

