This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: GCC ignores function attributes


On 12/06/14 03:31, Jonathan Wakely wrote:
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")));

I've found that this also works:

__attribute__((visibility("hidden"))) const SDL_AudioSpec& spec();

The only one that doesn't, is the documented one :-/  Documentation bug?


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]