Re: GCC ignores function attributes

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 12 June 2014 01:42, Nikos Chantziaras <realnc@xxxxxxxxx> wrote:
> 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?

No, the example in the documentation is a function with a void return,
and in that case the attribute binds to the function not the return
type.  Your function does not have a void return type.  I don't know
why that's different, but both the C and C++ compilers treat the
example the same.




[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux