aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDouglas Gregor <dgregor@apple.com>2012-02-01 17:18:19 +0000
committerDouglas Gregor <dgregor@apple.com>2012-02-01 17:18:19 +0000
commitb710dfe5231b0cd44dd987b9bd33c7f6ac165807 (patch)
tree67a84b12726775cd28624a0f3e37c93f106bb7c4
parenta1f2114d9e81923c750f6b439302ac03552c37db (diff)
Diagnose the restriction on default arguments in C++11 [expr.prim.lambda]p5.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@149517 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--lib/Sema/SemaExprCXX.cpp8
-rw-r--r--test/CXX/expr/expr.prim/expr.prim.lambda/p5.cpp7
2 files changed, 14 insertions, 1 deletions
diff --git a/lib/Sema/SemaExprCXX.cpp b/lib/Sema/SemaExprCXX.cpp
index c7daa80761..7e97b2919b 100644
--- a/lib/Sema/SemaExprCXX.cpp
+++ b/lib/Sema/SemaExprCXX.cpp
@@ -4886,9 +4886,15 @@ void Sema::ActOnStartOfLambdaDefinition(LambdaIntroducer &Intro,
// C++11 [expr.prim.lambda]p5:
// 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. It is neither virtual nor declared volatile.
+ // by mutable. It is neither virtual nor declared volatile. [...]
if (!FTI.hasMutableQualifier())
FTI.TypeQuals |= DeclSpec::TQ_const;
+
+ // C++11 [expr.prim.lambda]p5:
+ // [...] Default arguments (8.3.6) shall not be specified in the
+ // parameter-declaration-clause of a lambda-declarator.
+ CheckExtraCXXDefaultArguments(ParamInfo);
+
MethodTyInfo = GetTypeForDeclarator(ParamInfo, CurScope);
// FIXME: Can these asserts actually fail?
assert(MethodTyInfo && "no type from lambda-declarator");
diff --git a/test/CXX/expr/expr.prim/expr.prim.lambda/p5.cpp b/test/CXX/expr/expr.prim/expr.prim.lambda/p5.cpp
new file mode 100644
index 0000000000..a6fca9b2c4
--- /dev/null
+++ b/test/CXX/expr/expr.prim/expr.prim.lambda/p5.cpp
@@ -0,0 +1,7 @@
+// RUN: %clang_cc1 -std=c++11 %s -verify
+
+int test_default_args() {
+ [](int i = 5, // expected-error{{default arguments can only be specified for parameters in a function declaration}} \
+ // expected-error{{lambda expressions are not supported yet}}
+ int j = 17) {}; // expected-error{{default arguments can only be specified for parameters in a function declaration}}
+}