https://gcc.gnu.org/bugzilla/show_bug.cgi?id=99804
Bug ID: 99804 Summary: cannot convert bit field enum to its own type in a template member function Product: gcc Version: unknown Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: phonyuc at outlook dot com Target Milestone: --- struct S { enum E { A, B } e : 1; // line 2 void f1(decltype(e)) {} // line 3 template <typename> void f2() { f1(e); } // line 4 }; // ------ end-of-code ------ gcc (version 10.2 and earlier) won't compile this structure. Compilation will success if any one of the following changes is made: 1. (in line 2) the member is not in enumeration type 2. (in line 2) the member is not in bit field 3. (in line 2) the width is the same as the underlying type 4. (in line 3) f1 is not a member function of S 5. (in line 4) f2 is not a member function of S 6. (in line 4) f2 is not a template function 7. (in line 4) call with a static enum value: f1(E::A) 8. (in line 4) cast the variable into its own type: f1((decltype(e))e) The context looks similar to bug 92859 but the behaviour is different. // ------ compiler output ------ $ g++ -c bit-enum-template.cc a.cc: In member function 'void S::f2()': a.cc:4:40: error: cannot convert 'unsigned char:1' to 'S::E' 4 | template <typename> void f2() { f1(e); } // line 4 | ^ | | | unsigned char:1 a.cc:3:13: note: initializing argument 1 of 'void S::f1(S::E)' 3 | void f1(decltype(e)) {} // line 3 | ^~~~~~~~