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

* [Bug c++/99804] cannot convert bit field enum to its own type in a template member function
  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 ` pinskia at gcc dot gnu.org
  2022-02-12  3:11 ` pinskia at gcc dot gnu.org
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: pinskia at gcc dot gnu.org @ 2021-07-31 23:25 UTC (permalink / raw)
  To: gcc-bugs

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

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |NEW
     Ever confirmed|0                           |1
   Last reconfirmed|                            |2021-07-31
           See Also|                            |https://gcc.gnu.org/bugzill
                   |                            |a/show_bug.cgi?id=95009

--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Confirmed.

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

* [Bug c++/99804] cannot convert bit field enum to its own type in a template member function
  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
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: pinskia at gcc dot gnu.org @ 2022-02-12  3:11 UTC (permalink / raw)
  To: gcc-bugs

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

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |vofogi5810 at goonby dot com

--- Comment #2 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
*** Bug 104509 has been marked as a duplicate of this bug. ***

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

* [Bug c++/99804] cannot convert bit field enum to its own type in a template member function
  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
  4 siblings, 0 replies; 6+ messages in thread
From: mpolacek at gcc dot gnu.org @ 2023-10-23 15:43 UTC (permalink / raw)
  To: gcc-bugs

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

Marek Polacek <mpolacek at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |mpolacek at gcc dot gnu.org

--- Comment #3 from Marek Polacek <mpolacek at gcc dot gnu.org> ---
Fixed by r14-4793-gdad311874ac3b3, strange.

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

* [Bug c++/99804] cannot convert bit field enum to its own type in a template member function
  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
                   ` (2 preceding siblings ...)
  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
  4 siblings, 0 replies; 6+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2023-10-25 13:06 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #4 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Patrick Palka <ppalka@gcc.gnu.org>:

https://gcc.gnu.org/g:fb28d5c6b0a47ab704290d0122f978d1e6346551

commit r14-4924-gfb28d5c6b0a47ab704290d0122f978d1e6346551
Author: Patrick Palka <ppalka@redhat.com>
Date:   Wed Oct 25 09:03:52 2023 -0400

    c++: add fixed testcase [PR99804]

    We accept the non-dependent call f(e) here ever since the
    NON_DEPENDENT_EXPR removal patch r14-4793-gdad311874ac3b3.
    I haven't looked closely into why but I suspect wrapping 'e'
    in a NON_DEPENDENT_EXPR was causing the argument conversion
    to misbehave.

            PR c++/99804

    gcc/testsuite/ChangeLog:

            * g++.dg/template/enum9.C: New test.

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

* [Bug c++/99804] cannot convert bit field enum to its own type in a template member function
  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
                   ` (3 preceding siblings ...)
  2023-10-25 13:06 ` cvs-commit at gcc dot gnu.org
@ 2023-10-25 13:07 ` ppalka at gcc dot gnu.org
  4 siblings, 0 replies; 6+ messages in thread
From: ppalka at gcc dot gnu.org @ 2023-10-25 13:07 UTC (permalink / raw)
  To: gcc-bugs

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

Patrick Palka <ppalka at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
         Resolution|---                         |FIXED
   Target Milestone|---                         |14.0
                 CC|                            |ppalka at gcc dot gnu.org
             Status|NEW                         |RESOLVED

--- Comment #5 from Patrick Palka <ppalka at gcc dot gnu.org> ---
(In reply to Marek Polacek from comment #3)
> Fixed by r14-4793-gdad311874ac3b3, strange.

Yay :) thus incidentally fixed for GCC 14.

^ 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).