public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/99804] New: cannot convert bit field enum to its own type in a template member function
@ 2021-03-28 18:37 phonyuc at outlook dot com
  2021-07-31 23:25 ` [Bug c++/99804] " pinskia at gcc dot gnu.org
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: phonyuc at outlook dot com @ 2021-03-28 18:37 UTC (permalink / raw)
  To: gcc-bugs

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
      |             ^~~~~~~~

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2023-10-25 13:07 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-03-28 18:37 [Bug c++/99804] New: cannot convert bit field enum to its own type in a template member function phonyuc at outlook dot com
2021-07-31 23:25 ` [Bug c++/99804] " pinskia at gcc dot gnu.org
2022-02-12  3:11 ` pinskia at gcc dot gnu.org
2023-10-23 15:43 ` mpolacek at gcc dot gnu.org
2023-10-25 13:06 ` cvs-commit at gcc dot gnu.org
2023-10-25 13:07 ` ppalka at gcc dot gnu.org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).