diff options
author | Benjamin Kramer <benny.kra@googlemail.com> | 2012-12-06 15:42:21 +0000 |
---|---|---|
committer | Benjamin Kramer <benny.kra@googlemail.com> | 2012-12-06 15:42:21 +0000 |
commit | 42427409fd75a48381071e6da008a3c06897437a (patch) | |
tree | a861c02ea070784747efa0ed21d69137a281e1f3 | |
parent | 112aff155bae8fe11dce976dfd6e70285a769c3e (diff) |
Sema: Don't emit a warning when __func__ is used in a lambda outside of a function.
Fixes PR14518.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@169510 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r-- | lib/Sema/SemaExpr.cpp | 10 | ||||
-rw-r--r-- | test/SemaCXX/lambda-expressions.cpp | 4 |
2 files changed, 12 insertions, 2 deletions
diff --git a/lib/Sema/SemaExpr.cpp b/lib/Sema/SemaExpr.cpp index 67b1a7a764..7656d9ee66 100644 --- a/lib/Sema/SemaExpr.cpp +++ b/lib/Sema/SemaExpr.cpp @@ -2571,8 +2571,14 @@ ExprResult Sema::ActOnPredefinedExpr(SourceLocation Loc, tok::TokenKind Kind) { // string. Decl *currentDecl = getCurFunctionOrMethodDecl(); - if (!currentDecl && getCurBlock()) - currentDecl = getCurBlock()->TheDecl; + // Blocks and lambdas can occur at global scope. Don't emit a warning. + if (!currentDecl) { + if (const BlockScopeInfo *BSI = getCurBlock()) + currentDecl = BSI->TheDecl; + else if (const LambdaScopeInfo *LSI = getCurLambda()) + currentDecl = LSI->CallOperator; + } + if (!currentDecl) { Diag(Loc, diag::ext_predef_outside_function); currentDecl = Context.getTranslationUnitDecl(); diff --git a/test/SemaCXX/lambda-expressions.cpp b/test/SemaCXX/lambda-expressions.cpp index 6f92373a69..a333f38530 100644 --- a/test/SemaCXX/lambda-expressions.cpp +++ b/test/SemaCXX/lambda-expressions.cpp @@ -236,3 +236,7 @@ namespace PR13860 { namespace PR13854 { auto l = [](void){}; } + +namespace PR14518 { + auto f = [](void) { return __func__; }; // no-warning +} |