1

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?

xmllmx
  • 39,765
  • 26
  • 162
  • 323
  • 5
    This bug seemed to have been [reported](https://bugs.llvm.org/show_bug.cgi?id=50205) by me before which was fixed in trunk. – 康桓瑋 Dec 12 '21 at 15:55

0 Answers0