https://gcc.gnu.org/bugzilla/show_bug.cgi?id=92343

            Bug ID: 92343
           Summary: [[likely]]/[[unlikely]] prevent method from being a
                    constant expression
           Product: gcc
           Version: unknown
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: Darrell.Wright at gmail dot com
  Target Milestone: ---

Adding the attributes likely or unlikely can cause a function to be a constant
expression

https://gcc.godbolt.org/z/DGzPoa

#include <cstddef>
#include <cstdlib>

template <typename B, size_t N>
constexpr bool test(B&& b, char const (&reason)[N]) {
  [[unlikely]] if (not static_cast<bool>(b)) {
    (void)reason;
    std::abort();
  }
  return true;
}

static_assert( test( true, "testing" ) )

Reply via email to