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

            Bug ID: 104509
           Summary: Scoped enum as bit field in a function template
           Product: gcc
           Version: 11.1.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: vofogi5810 at goonby dot com
  Target Milestone: ---

The following fails:

#include <cassert>

struct test {
  enum class state { off, on };
  state st: 1; // bit field
  bool is_on() const {
    return st == state::on; // this is ok
  }
  template<bool flag>
  bool is() const {
    if constexpr (flag) return st == state::on; // error?
    else return st == state::off;
  }
};

int main() {
  test t{test::state::on};
  return !t.is<true>();
}

GCC output:

error: no match for ‘operator==’ (operand types are ‘const signed char:1’ and
‘test::state’)

Non-template function works. Current workaround is to apply static_cast.
  • [Bug c++/104509] New: Scoped enu... vofogi5810 at goonby dot com via Gcc-bugs

Reply via email to