DR974: Lambdas can have default arguments.

llvm-svn: 179688
This commit is contained in:
Richard Smith 2013-04-17 16:25:20 +00:00
parent 9c2ccd622f
commit 3cb4c63073
5 changed files with 6 additions and 22 deletions

View File

@ -254,7 +254,6 @@ def : DiagGroup<"strict-overflow=5">;
def : DiagGroup<"strict-overflow">;
def InvalidOffsetof : DiagGroup<"invalid-offsetof">;
def LambdaExtensions : DiagGroup<"lambda-extensions">;
def : DiagGroup<"strict-prototypes">;
def StrictSelector : DiagGroup<"strict-selector-match">;
def MethodDuplicate : DiagGroup<"duplicate-method-match">;

View File

@ -4789,9 +4789,6 @@ let CategoryName = "Lambda Issue" in {
"incomplete result type %0 in lambda expression">;
def err_lambda_objc_object_result : Error<
"non-pointer Objective-C class type %0 in lambda expression result">;
def ext_lambda_default_arguments : ExtWarn<
"C++11 forbids default arguments for lambda expressions">,
InGroup<LambdaExtensions>;
def err_noreturn_lambda_has_return_expr : Error<
"lambda declared 'noreturn' should not return">;
def warn_maybe_falloff_nonvoid_lambda : Warning<

View File

@ -636,22 +636,12 @@ void Sema::CheckCXXDefaultArguments(FunctionDecl *FD) {
bool IsLambda = FD->getOverloadedOperator() == OO_Call &&
isa<CXXMethodDecl>(FD) &&
cast<CXXMethodDecl>(FD)->getParent()->isLambda();
// Find first parameter with a default argument
for (p = 0; p < NumParams; ++p) {
ParmVarDecl *Param = FD->getParamDecl(p);
if (Param->hasDefaultArg()) {
// C++11 [expr.prim.lambda]p5:
// [...] Default arguments (8.3.6) shall not be specified in the
// parameter-declaration-clause of a lambda-declarator.
//
// FIXME: Core issue 974 strikes this sentence, we only provide an
// extension warning.
if (IsLambda)
Diag(Param->getLocation(), diag::ext_lambda_default_arguments)
<< Param->getDefaultArgRange();
if (Param->hasDefaultArg())
break;
}
}
// C++ [dcl.fct.default]p4:

View File

@ -1,4 +1,4 @@
// RUN: %clang_cc1 -fsyntax-only -std=c++11 %s -Wno-lambda-extensions -verify
// 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; };

View File

@ -39,12 +39,10 @@ void test_quals() {
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.
// Note: Removed by core issue 974.
// 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, // expected-warning{{C++11 forbids default arguments for lambda expressions}}
int j = 17) { return i+j;}(5, 6);
return [](int i = 5, int j = 17) { return i+j;}(5, 6);
}
// Any exception-specification specified on a lambda-expression