[cfe-commits] r169510 - in /cfe/trunk: lib/Sema/SemaExpr.cpp test/SemaCXX/lambda-expressions.cpp
Benjamin Kramer
benny.kra at googlemail.com
Thu Dec 6 07:42:21 PST 2012
Author: d0k
Date: Thu Dec 6 09:42:21 2012
New Revision: 169510
URL: http://llvm.org/viewvc/llvm-project?rev=169510&view=rev
Log:
Sema: Don't emit a warning when __func__ is used in a lambda outside of a function.
Fixes PR14518.
Modified:
cfe/trunk/lib/Sema/SemaExpr.cpp
cfe/trunk/test/SemaCXX/lambda-expressions.cpp
Modified: cfe/trunk/lib/Sema/SemaExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExpr.cpp?rev=169510&r1=169509&r2=169510&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaExpr.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExpr.cpp Thu Dec 6 09:42:21 2012
@@ -2571,8 +2571,14 @@
// 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();
Modified: cfe/trunk/test/SemaCXX/lambda-expressions.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/lambda-expressions.cpp?rev=169510&r1=169509&r2=169510&view=diff
==============================================================================
--- cfe/trunk/test/SemaCXX/lambda-expressions.cpp (original)
+++ cfe/trunk/test/SemaCXX/lambda-expressions.cpp Thu Dec 6 09:42:21 2012
@@ -236,3 +236,7 @@
namespace PR13854 {
auto l = [](void){};
}
+
+namespace PR14518 {
+ auto f = [](void) { return __func__; }; // no-warning
+}
More information about the cfe-commits
mailing list