Sema: Don't emit a warning when __func__ is used in a lambda outside of a function.

Fixes PR14518.

llvm-svn: 169510
This commit is contained in:
Benjamin Kramer 2012-12-06 15:42:21 +00:00
parent 8ccff08f76
commit 6928cf7826
2 changed files with 12 additions and 2 deletions

View File

@ -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();

View File

@ -236,3 +236,7 @@ namespace PR13860 {
namespace PR13854 {
auto l = [](void){};
}
namespace PR14518 {
auto f = [](void) { return __func__; }; // no-warning
}