struct S {
constexpr bool operator==(int) const { return false; }
};
template<class T> int f() {
while (T() == 0) [[likely]] {
return 0;
}
}
template int f<S>();
template int f<int>();
Clang correctly diagnoses one warning for f<S> and one warning for f<int>:
<source>:9:1: warning: non-void function does not return a value [-Wreturn-type]
9 | }
| ^
<source>:11:14: note: in instantiation of function template specialization 'f<S>' requested here
11 | template int f<S>();
| ^
<source>:6:24: warning: attribute 'likely' has no effect when annotating an infinite loop [-Wignored-attributes]
6 | while (T() == 0) [[likely]] {
| ^~~~~~
<source>:6:5: note: annotating the infinite loop here
6 | while (T() == 0) [[likely]] {
| ^~~~~~~~~~~~~~~~
2 warnings generated.
The -Wreturn-type warning (produced by Sema) helpfully includes a note pointing the user at f<S>.
The -Wignored-attributes warning (produced by CodeGen) unhelpfully doesn't include any note pointing the user at f<int>.
Presumably that information is difficult to come by, in CodeGen, but it sure would be useful.
https://godbolt.org/z/4MGx14osY
Clang correctly diagnoses one warning for
f<S>
and one warning forf<int>
:The
-Wreturn-type
warning (produced by Sema) helpfully includes a note pointing the user atf<S>
. The-Wignored-attributes
warning (produced by CodeGen) unhelpfully doesn't include any note pointing the user atf<int>
. Presumably that information is difficult to come by, in CodeGen, but it sure would be useful.