[PATCH] Attribute parsing following labels

Aaron Ballman aaron at aaronballman.com
Fri Nov 15 06:45:36 PST 2013


Ping

On Wed, Oct 30, 2013 at 6:16 PM, Aaron Ballman <aaron at aaronballman.com> wrote:
> Finally have some spare time to look into this again, thank you for
> your patience.  :-)
>
> On Tue, Oct 15, 2013 at 12:46 AM, Richard Smith <richard at metafoo.co.uk> wrote:
>> +      SourceLocation Loc = Tok.getLocation();
>>
>> Unused variable.
>>
>> +      // If the SubStmt is invalid, we want the attributes to attach to the
>> +      // label instead.
>> +      if (!SubStmt.isUsable() || SubStmt.isInvalid())
>> +        attrs.takeAllFrom(TempAttrs);
>>
>> I thought your experiments showed the attributes were ill-formed in this
>> case.
>
> Since it's been a while, I went back to re-test my experiments, and I
> think I made a mistake.
>
> void f() {
>     A:
>       __attribute__((unused)) int i; // attribute applies to variable
>     B:
>       __attribute__((unused)); // attribute applies to label
>
>     C:
>       __attribute__((unused))
>       #pragma weak unused_local_static
>       ;
>
>     D:
>       #pragma weak unused_local_static
>       __attribute__((unused))
>       ;
> }
>
> *Both* of these cases generate errors in gcc. What I didn't realize is
> that gcc stopped trying to report errors with D because C was
> ill-formed.
>
> With D commented out, I get:
>
> prog.cpp: In function ‘void f()’:
> prog.cpp:8:7: error: expected primary-expression before ‘__attribute__’
>        __attribute__((unused))
>        ^
> prog.cpp:8:7: error: expected ‘;’ before ‘__attribute__’
> prog.cpp:9:39: error: expected ‘}’ before end of line
>        #pragma weak unused_local_static
>                                        ^
> prog.cpp:2:5: warning: label ‘A’ defined but not used [-Wunused-label]
>      A:
>      ^
> prog.cpp:7:5: warning: label ‘C’ defined but not used [-Wunused-label]
>      C:
>      ^
> prog.cpp: At global scope:
> prog.cpp:9:39: error: expected declaration before end of line
>        #pragma weak unused_local_static
>
> With C commented out, I get:
>
> prog.cpp: In function ‘void f()’:
> prog.cpp:14:7: error: expected primary-expression before ‘__attribute__’
>        __attribute__((unused))
>        ^
> prog.cpp:14:7: error: expected ‘;’ before ‘__attribute__’
> prog.cpp:2:5: warning: label ‘A’ defined but not used [-Wunused-label]
>      A:
>      ^
> prog.cpp:12:5: warning: label ‘D’ defined but not used [-Wunused-label]
>      D:
>      ^
>
> So I've created a new patch that I believe has the correct behavior.
> If there's a semi-colon, the attributes are applied to the label.  If
> there's a declaration, it is handled.  Any other form of statement
> causes a specific error.
>
> Thanks!
>
> ~Aaron




More information about the cfe-commits mailing list