GCC ignores function attributes
Jonathan Wakely
jwakely.gcc@gmail.com
Thu Jun 12 07:51:00 GMT 2014
On 11 June 2014 23:36, Nikos Chantziaras wrote:
> According to the documentation:
>
> https://gcc.gnu.org/onlinedocs/gcc-4.8.2/gcc/Function-Attributes.html#Function-Attributes
>
> and more specific, the example about the visibility attribute:
>
> void __attribute__ ((visibility ("protected")))
> f () { /* Do something. */; }
>
> doesn't work for me. I have this C++ function prototype:
>
> const SDL_AudioSpec& __attribute__((visibility("default")))
> spec();
>
> Compiling this with g++ 4.8.2 gives me:
>
> warning: 'visibility' attribute ignored on non-class types
I think the attribute binds to the return type here, which is a
reference (not a class type) so can't be given visibility.
This applies the attribute to the function, not the return type:
const SDL_AudioSpec& spec() __attribute__((visibility("hidden")));
More information about the Gcc-help
mailing list