<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/118697>118697</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
Clang mishandles GNU attributes on function declarations with trailing return type
</td>
</tr>
<tr>
<th>Labels</th>
<td>
clang
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
zygoloid
</td>
</tr>
</table>
<pre>
[Testcase demonstrating GCC behavior](https://godbolt.org/z/Trc91rY7d):
```c++
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.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJyEVUtv4zgT_DX0pRFDphU_Djrk8Xkwlw97yGKwJ6NFtizuUqTBbsVQfv2Csh3bs84MIMAPktVV1aUmMrtdIKrU47N6fJ1gL21M1cewiz46O6mjHfLaG7EYZAJLXQwsCcWFHXx7eYGaWnx3ManHV6VXrcie1fxJ6Y3Sm120dfQyjWmn9OZD6c1bMutZ-mtplV7nbcX4LIrjY5R-zk_xhL1EaJReKb2GBzX_H9QxethuUSS5uhfabsfVVYiJpE8hA2bMX5xWy2c4bgZJPan5M6jl65HDeGR3fcQFuVfvnYzEtGX3QUqvylPZm8r_gfm68Fn5kUT2UxKhMEhLoBbFp7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