-
Notifications
You must be signed in to change notification settings - Fork 14.5k
Description
Testcase demonstrating GCC behavior:
auto f() -> bool __attribute__((noreturn));
auto f() -> bool { return true; }
auto g() -> int __attribute__((vector_size(4)));
auto g() -> int { return true; }
GCC treats the noreturn
attribute as applying to the function, and warns on the function definition because it does return.
GCC treats the vector_size
attribute as applying to the return type, and rejects the definition because it specifies a different return type.
Clang treats the attribute as always applying to the return type. This seems like a missing case of GNU attribute "sliding".
FWIW, I encountered this specifically for the diagnose_if
attribute, which can only be written as a GNU attribute, and because its argument references function parameters, can only be written in trailing position in a function declaration. There appears to currently be no way to combine trailing return types with the diagnose_if
attribute (and other attributes like it, such as enable_if
and the thread-safety annotations), which is a problem for coding styles / standards that mandate the use of trailing return types.
Presumably Clang should slide non-type attributes from a trailing return type onto the function declarator.