]> granicus.if.org Git - clang/commitdiff
Sema: Don't emit a warning when __func__ is used in a lambda outside of a function.
authorBenjamin Kramer <benny.kra@googlemail.com>
Thu, 6 Dec 2012 15:42:21 +0000 (15:42 +0000)
committerBenjamin Kramer <benny.kra@googlemail.com>
Thu, 6 Dec 2012 15:42:21 +0000 (15:42 +0000)
Fixes PR14518.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@169510 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Sema/SemaExpr.cpp
test/SemaCXX/lambda-expressions.cpp

index 67b1a7a76426c83cc07c36d8370abbc913ab7711..7656d9ee66745d04731b43ee47e45f6f8d33cd2b 100644 (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();
index 6f92373a69540771d54b7cb7d18c742796419932..a333f38530b3837a93430db2d2325ca377c84d9c 100644 (file)
@@ -236,3 +236,7 @@ namespace PR13860 {
 namespace PR13854 {
   auto l = [](void){};
 }
+
+namespace PR14518 {
+  auto f = [](void) { return __func__; }; // no-warning
+}