From 6928cf78262ef71b2f8f560533e064277960b685 Mon Sep 17 00:00:00 2001 From: Benjamin Kramer Date: Thu, 6 Dec 2012 15:42:21 +0000 Subject: [PATCH] Sema: Don't emit a warning when __func__ is used in a lambda outside of a function. Fixes PR14518. llvm-svn: 169510 --- clang/lib/Sema/SemaExpr.cpp | 10 ++++++++-- clang/test/SemaCXX/lambda-expressions.cpp | 4 ++++ 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp index 67b1a7a..7656d9e 100644 --- a/clang/lib/Sema/SemaExpr.cpp +++ b/clang/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/clang/test/SemaCXX/lambda-expressions.cpp b/clang/test/SemaCXX/lambda-expressions.cpp index 6f92373..a333f38 100644 --- a/clang/test/SemaCXX/lambda-expressions.cpp +++ b/clang/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 +} -- 2.7.4