[cfe-commits] r169510 - in /cfe/trunk: lib/Sema/SemaExpr.cpp test/SemaCXX/lambda-expressions.cpp
Benjamin Kramer
benny.kra at gmail.com
Thu Dec 6 08:32:00 PST 2012
On 06.12.2012, at 17:22, David Blaikie <dblaikie at gmail.com> wrote:
> On Thu, Dec 6, 2012 at 7:42 AM, Benjamin Kramer
> <benny.kra at googlemail.com> wrote:
>> 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
>
> Just out of curiosity: what does this actually expand to in this
> context? Should we test the expansion is what we expect it to be? (is
> there a separate/interesting codepath for it that's not being verified
> by other tests?)
That's handled by IRGen later. It emits "operator()". Not sure if that's the best string for the lambda but it matches GCC's behavior.
- Ben
>
>> +}
>>
>>
>> _______________________________________________
>> cfe-commits mailing list
>> cfe-commits at cs.uiuc.edu
>> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits
More information about the cfe-commits
mailing list