The following code is accepted by gcc 11.2, but rejected by clang 13:
struct A
{
int n = 0;
constexpr operator int() const noexcept
{
if (n >= 2) [[unlikely]]
{
return 2;
}
else if (n >= 1) [[likely]]
{
return 1;
}
else [[unlikely]]
{
return 0;
}
}
};
int main()
{}
The clang 13's error message:
error: no return statement in constexpr function
constexpr operator int() const noexcept
^
See https://godbolt.org/z/69Gdezqvz
Is this a bug of clang-13 on [[likely]]
attribute?