Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unbalanced parenthesis using __attribute__ in g++

Today I tried clang on a project I have developed some time ago. I was suprised when it encountered a compilation error, since I had compiled my project successfully using g++.

This short snippet reproduces the line where the error was encountered:

int main() {
    __attribute__((aligned(16)) char arr[5];
}

Which produces this error:

test.cpp:2:32: error: expected ')'
    __attribute__((aligned(16)) char arr[5];
                               ^
                               )

As you can see, there is an umbalanced parenthesis. There are three '(', and two ')'. This clearly looks like it should actually produce a compilation error.

Is this a valid usage of this keyword? I can't seem to find anything on the documentation that indicates it is.

I'm using g++ 4.5.2 and clang 2.8.

Note that this error is detected when using gcc instead of g++.

like image 373
mfontanini Avatar asked May 16 '12 02:05

mfontanini


1 Answers

This would be a compiler bug. The compiler sees __attribute__ followed by two opening parentheses, some other tokens and then two closing parentheses, which is probably the “definition” of what an __attribute__ should look like, e.g.

<attribute> ::= __attribute__ '((' something '))'

My guess is that the tokens in between are being interpreted as aligned(16 and by some miracle it still works.

like image 71
dreamlax Avatar answered Nov 09 '22 08:11

dreamlax