public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/107460] New: ICE with "using enum" member passed to template function (g++ 11.x-13)
@ 2022-10-30  6:08 chris-gcc-bugzilla at cybermato dot com
  2022-10-30  6:09 ` [Bug c++/107460] " chris-gcc-bugzilla at cybermato dot com
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: chris-gcc-bugzilla at cybermato dot com @ 2022-10-30  6:08 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 107460
           Summary: ICE with "using enum" member passed to template
                    function (g++ 11.x-13)
           Product: gcc
           Version: 12.1.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: chris-gcc-bugzilla at cybermato dot com
  Target Milestone: ---

Created attachment 53793
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=53793&action=edit
file generated by -freport-bug

The following code (also attached) causes an ICE in tsubst_copy on every
version of g++ that can handle "using enum", with either -std=c++20 or
-std=gnu++20, regardless of -O0, -O1, -O2, etc.:

  trunk (13.0.0 20221028)  (Godbolt)
  12.2.0  (Godbolt)
  12.1.0  (Ubuntu 22.04)
  11.3.0  (Godbolt)
  11.2.0  (Ubuntu 22.04)
  11.1    (Ubuntu 20.04)
  (10.4 and earlier don't seem to support "using enum")

clang 13, 14, and 15 compile it with no complaint, as does MSVC (19.33 per
Godbolt, plus VS 2019 and VS 2022).

If I pass 'EventCat::kEventCat_Min' to boundsCheck() instead of just
'kEventCat_Min', it compiles without error.

---------------------------------------------------------------------------------
void fatal [[noreturn]] (const char * msg);

template <typename ToType, typename FromType, typename MinType>
ToType boundsCheck(const FromType & value, const MinType & min)
{
    if (int(value) >= int(min))
    {
        return static_cast<ToType>(value);
    }

    fatal ("nope");
}

enum class EventCat
{
    kEventCat_NeverUseThis = 0,
    kUninitialized,
    kTesting,

    kEventCat_Min = kEventCat_NeverUseThis + 1,
};

struct Event
{
    using enum EventCat;

    Event(EventCat a_category, auto)
        : category(a_category)
    {
        boundsCheck<EventCat>(a_category, kEventCat_Min);  // using
"EventCat::kEventCat_Min" instead of just "kEventCat_Min" makes this not fail
    }

    EventCat category = EventCat::kUninitialized;
};

void foo()
{
    Event(EventCat::kTesting, 0);
}
---------------------------------------------------------------------------------
On Ubuntu 22.04 using g++-12 (Ubuntu 12.1.0-2ubuntu1~22.04) 12.1.0:

$ g++-12 -c -std=c++20 g++-ice-in-tsubst_copy.cpp
g++-ice-in-tsubst_copy.cpp: In instantiation of ‘Event::Event(EventCat, auto:1)
[with auto:1 = int]’:
g++-ice-in-tsubst_copy.cpp:38:32:   required from here
g++-ice-in-tsubst_copy.cpp:30:30: internal compiler error: in tsubst_copy, at
cp/pt.cc:16919
   30 |         boundsCheck<EventCat>(a_category, kEventCat_Min);  // using
"EventCat::kEventCat_Min" instead of just "kEventCat_Min" makes this not fail
      |         ~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
0x661b9b tsubst_copy
        ../../src/gcc/cp/pt.cc:16919
0x80f2ce tsubst_copy_and_build(tree_node*, tree_node*, int, tree_node*, bool,
bool)
        ../../src/gcc/cp/pt.cc:21399
0x81e961 tsubst_copy_and_build_call_args
        ../../src/gcc/cp/pt.cc:19937
0x80f8c0 tsubst_copy_and_build(tree_node*, tree_node*, int, tree_node*, bool,
bool)
        ../../src/gcc/cp/pt.cc:20687
0x8200e8 tsubst_expr(tree_node*, tree_node*, int, tree_node*, bool)
        ../../src/gcc/cp/pt.cc:19491
0x821097 tsubst_expr(tree_node*, tree_node*, int, tree_node*, bool)
        ../../src/gcc/cp/pt.cc:18462
0x821097 tsubst_expr(tree_node*, tree_node*, int, tree_node*, bool)
        ../../src/gcc/cp/pt.cc:18504
0x820c28 tsubst_expr(tree_node*, tree_node*, int, tree_node*, bool)
        ../../src/gcc/cp/pt.cc:18462
0x820c28 tsubst_expr(tree_node*, tree_node*, int, tree_node*, bool)
        ../../src/gcc/cp/pt.cc:18833
0x821632 tsubst_expr(tree_node*, tree_node*, int, tree_node*, bool)
        ../../src/gcc/cp/pt.cc:18462
0x821632 tsubst_expr(tree_node*, tree_node*, int, tree_node*, bool)
        ../../src/gcc/cp/pt.cc:18476
0x820c28 tsubst_expr(tree_node*, tree_node*, int, tree_node*, bool)
        ../../src/gcc/cp/pt.cc:18462
0x820c28 tsubst_expr(tree_node*, tree_node*, int, tree_node*, bool)
        ../../src/gcc/cp/pt.cc:18833
0x81f63c tsubst_expr(tree_node*, tree_node*, int, tree_node*, bool)
        ../../src/gcc/cp/pt.cc:26412
0x81f63c instantiate_body
        ../../src/gcc/cp/pt.cc:26412
0x81ff09 instantiate_decl(tree_node*, bool, bool)
        ../../src/gcc/cp/pt.cc:26704
0x834bdb instantiate_pending_templates(int)
        ../../src/gcc/cp/pt.cc:26783
0x739197 c_parse_final_cleanups()
        ../../src/gcc/cp/decl2.cc:5128
Please submit a full bug report, with preprocessed source (by using
-freport-bug).
Please include the complete backtrace with any bug report.
See <file:///usr/share/doc/gcc-12/README.Bugs> for instructions.

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

* [Bug c++/107460] ICE with "using enum" member passed to template function (g++ 11.x-13)
  2022-10-30  6:08 [Bug c++/107460] New: ICE with "using enum" member passed to template function (g++ 11.x-13) chris-gcc-bugzilla at cybermato dot com
@ 2022-10-30  6:09 ` chris-gcc-bugzilla at cybermato dot com
  2022-10-30 18:52 ` pinskia at gcc dot gnu.org
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: chris-gcc-bugzilla at cybermato dot com @ 2022-10-30  6:09 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #1 from Chris MacGregor <chris-gcc-bugzilla at cybermato dot com> ---
Created attachment 53794
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=53794&action=edit
preprocessed source

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

* [Bug c++/107460] ICE with "using enum" member passed to template function (g++ 11.x-13)
  2022-10-30  6:08 [Bug c++/107460] New: ICE with "using enum" member passed to template function (g++ 11.x-13) chris-gcc-bugzilla at cybermato dot com
  2022-10-30  6:09 ` [Bug c++/107460] " chris-gcc-bugzilla at cybermato dot com
@ 2022-10-30 18:52 ` pinskia at gcc dot gnu.org
  2022-10-30 18:53 ` pinskia at gcc dot gnu.org
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: pinskia at gcc dot gnu.org @ 2022-10-30 18:52 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #2 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
<source>: In instantiation of 'Event::Event(EventCat, auto:1) [with auto:1 =
int]':
<source>:38:32:   required from here
<source>:30:30: internal compiler error: tree check: expected enumeral_type,
have record_type in tsubst_copy, at cp/pt.cc:17024
   30 |         boundsCheck<EventCat>(a_category, kEventCat_Min);  // using
"EventCat::kEventCat_Min" instead of just "kEventCat_Min" makes this not fail
      |         ~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~

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

* [Bug c++/107460] ICE with "using enum" member passed to template function (g++ 11.x-13)
  2022-10-30  6:08 [Bug c++/107460] New: ICE with "using enum" member passed to template function (g++ 11.x-13) chris-gcc-bugzilla at cybermato dot com
  2022-10-30  6:09 ` [Bug c++/107460] " chris-gcc-bugzilla at cybermato dot com
  2022-10-30 18:52 ` pinskia at gcc dot gnu.org
@ 2022-10-30 18:53 ` pinskia at gcc dot gnu.org
  2022-10-31  0:24 ` chris-gcc-bugzilla at cybermato dot com
  2022-10-31  0:32 ` pinskia at gcc dot gnu.org
  4 siblings, 0 replies; 6+ messages in thread
From: pinskia at gcc dot gnu.org @ 2022-10-30 18:53 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
         Resolution|---                         |DUPLICATE

--- Comment #3 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Duplicate of bug 105787.

*** This bug has been marked as a duplicate of bug 105787 ***

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

* [Bug c++/107460] ICE with "using enum" member passed to template function (g++ 11.x-13)
  2022-10-30  6:08 [Bug c++/107460] New: ICE with "using enum" member passed to template function (g++ 11.x-13) chris-gcc-bugzilla at cybermato dot com
                   ` (2 preceding siblings ...)
  2022-10-30 18:53 ` pinskia at gcc dot gnu.org
@ 2022-10-31  0:24 ` chris-gcc-bugzilla at cybermato dot com
  2022-10-31  0:32 ` pinskia at gcc dot gnu.org
  4 siblings, 0 replies; 6+ messages in thread
From: chris-gcc-bugzilla at cybermato dot com @ 2022-10-31  0:24 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #4 from Chris MacGregor <chris-gcc-bugzilla at cybermato dot com> ---
@Andrew, how did you get the output in comment #2, with "tree check: expected
enumeral_type, have record_type in tsubst_copy" in it?

Also, should this be marked as directly a dup of 103081, rather than as dup of
a dup (105787)?  (I did look at 103081, but it wasn't clear that it was
necessarily the same bug, since the upper part of the backtrace is different
from what I saw, and the lower part seems to be missing in the 103081 report.)

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

* [Bug c++/107460] ICE with "using enum" member passed to template function (g++ 11.x-13)
  2022-10-30  6:08 [Bug c++/107460] New: ICE with "using enum" member passed to template function (g++ 11.x-13) chris-gcc-bugzilla at cybermato dot com
                   ` (3 preceding siblings ...)
  2022-10-31  0:24 ` chris-gcc-bugzilla at cybermato dot com
@ 2022-10-31  0:32 ` pinskia at gcc dot gnu.org
  4 siblings, 0 replies; 6+ messages in thread
From: pinskia at gcc dot gnu.org @ 2022-10-31  0:32 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #5 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
(In reply to Chris MacGregor from comment #4)
> @Andrew, how did you get the output in comment #2, with "tree check:
> expected enumeral_type, have record_type in tsubst_copy" in it?

When gcc is configured --enable-checking=yes (or as on the development trunk it
is enabled by default)
Gcc has many extra internal checks to make sure things are not accessed
incorrectly but only enabled if requested for release builds as they introduce
some overhead on compile time.

> 
> Also, should this be marked as directly a dup of 103081, rather than as dup
> of a dup (105787)?  (I did look at 103081, but it wasn't clear that it was
> necessarily the same bug, since the upper part of the backtrace is different
> from what I saw, and the lower part seems to be missing in the 103081
> report.)

Yes. Though it does not matter that much as it does not change anything in
fixing the bug.

*** This bug has been marked as a duplicate of bug 103081 ***

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

end of thread, other threads:[~2022-10-31  0:32 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-10-30  6:08 [Bug c++/107460] New: ICE with "using enum" member passed to template function (g++ 11.x-13) chris-gcc-bugzilla at cybermato dot com
2022-10-30  6:09 ` [Bug c++/107460] " chris-gcc-bugzilla at cybermato dot com
2022-10-30 18:52 ` pinskia at gcc dot gnu.org
2022-10-30 18:53 ` pinskia at gcc dot gnu.org
2022-10-31  0:24 ` chris-gcc-bugzilla at cybermato dot com
2022-10-31  0:32 ` pinskia 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).