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

            Bug ID: 125983
           Summary: GCC ICE in tsubst with CTAD and decltype call
                    expression involving dependent type
           Product: gcc
           Version: 15.2.0
            Status: UNCONFIRMED
          Keywords: error-recovery, ice-checking, ice-on-invalid-code
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: attackerj1113 at gmail dot com
  Target Milestone: ---

This ICE occurs in GCC 12.1–15.2(assertions), but appears to be fixed in GCC
16.1. Reporting for regression tracking and test coverage.

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
template<class T>
struct A {
  using value_type = typename T::value_type;

  static value_type* helper(...);

  using pointer = decltype(helper((T*)0));
};

A(int) -> A<int>;

A a(0);
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
https://godbolt.org/z/E594K11P1

The issue seems to require the combination of:

>an invalid dependent member access (typename T::value_type with non-class T)

>a decltype of a call expression involving a dependent argument (helper((T*)0))

>CTAD triggering instantiation

Output:
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
<source>: In instantiation of 'struct A<int>':
<source>:12:6:   required from here
   12 | A a(0);
      |      ^
<source>:3:9: error: 'int' is not a class, struct, or union type
    3 |   using value_type = typename T::value_type;
      |         ^~~~~~~~~~
<source>:7:34: internal compiler error: Segmentation fault
    7 |   using pointer = decltype(helper((T*)0));
      |                            ~~~~~~^~~~~~~
0x31ce315 diagnostic_context::diagnostic_impl(rich_location*,
diagnostic_metadata const*, diagnostic_option_id, char const*, __va_list_tag
(*) [1], diagnostic_t)
        ???:0
0x31e52e6 internal_error(char const*, ...)
        ???:0
0x129abfd tsubst(tree_node*, tree_node*, int, tree_node*)
        ???:0
0x129b1a4 tsubst(tree_node*, tree_node*, int, tree_node*)
        ???:0
0x12c68f1 instantiate_class_template(tree_node*)
        ???:0
0x1136ec7 cp_finish_decl(tree_node*, tree_node*, bool, tree_node*, int,
cp_decomp*)
        ???:0
0x1263373 c_parse_file()
        ???:0
0x13c65c9 c_common_parse_file()
        ???:0
Please submit a full bug report, with preprocessed source (by using
-freport-bug).
Please include the complete backtrace with any bug report.
See <https://gcc.gnu.org/bugs/> for instructions.
Compiler returned: 1

Reply via email to