From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id B254A3858004; Sun, 28 Mar 2021 18:37:52 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org B254A3858004 From: "phonyuc at outlook dot com" To: gcc-bugs@gcc.gnu.org Subject: [Bug c++/99804] New: cannot convert bit field enum to its own type in a template member function Date: Sun, 28 Mar 2021 18:37:52 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: c++ X-Bugzilla-Version: unknown X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: phonyuc at outlook dot com X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Resolution: X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: bug_id short_desc product version bug_status bug_severity priority component assigned_to reporter target_milestone Message-ID: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 X-BeenThere: gcc-bugs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-bugs mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 28 Mar 2021 18:37:52 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D99804 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 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=20 a.cc: In member function 'void S::f2()': a.cc:4:40: error: cannot convert 'unsigned char:1' to 'S::E' 4 | template 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 | ^~~~~~~~=