GCC 4.9.1 is not like function declarations with a return type of a return type with attributes when the return type is a class.
Consider the following simplified test:
struct bar
{
int a;
bar (int a) : a(a) {}
};
auto foo() -> bar __attribute__((unused));
auto foo() -> bar { return bar(5); }
int main()
{
return 0;
}
GCC prints a strange warning regarding the attribute:
argh.cpp:2:41: warning: ignoring attributes applied to class type ‘bar’ outside of definition [-Wattributes]
auto foo() -> bar __attribute__((unused)) {return bar(5);}
Combining the declaration with the definition does not disable the warning, and this only happens when the return type is a class, it works fine with int. What's happening? Why doesn't GCC like this feature-specific declaration?
source
share