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

            Bug ID: 125677
           Summary: The C++ frontend fails to reject an invalid un-deduced
                    auto in a trailing return type when forming a function
                    reference type for a variable template instantiation.
                    This invalid AST is then passed to the backend,
                    causing a Segmentation fault (ICE) during t
           Product: gcc
           Version: 13.4.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: 1794833681 at qq dot com
  Target Milestone: ---

Description:
The C++ frontend fails to reject an invalid un-deduced auto in a trailing
return type when forming a function reference type for a variable template
instantiation. This invalid AST is then passed to the backend, causing a
Segmentation fault (ICE) during the RTL expansion phase.

Minimal Reproducible Example:

C++
template <typename a>
inline constexpr bool t = false;

int main()
{
    return t<auto(&)(const int*) -> auto&>;
}
Command Line Arguments:

Bash
g++ -std=c++23 source.cpp
Tested Versions:

Reproduced on: x86-64 gcc 11.3 up to x86-64 gcc 13.4 (including builds with
assertions enabled).

Compiler Output / Backtrace:

Plaintext
<source>: In function 'int main()':
<source>:6:12: internal compiler error: Segmentation fault
    6 |     return t<auto(&)(const int*) -> auto&>;
      |            ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
0x1bb069e internal_error(char const*, ...)
        ???:0
0x10eb0c3 make_decl_rtl(tree_node*)
        ???:0
0xaa8bc3 expand_expr_real_1(tree_node*, rtx_def*, machine_mode,
expand_modifier, rtx_def**, bool)
        ???:0
0xab4219 store_expr(tree_node*, rtx_def*, int, bool, bool)
        ???:0
Please submit a full bug report, with preprocessed source (by using
-freport-bug).
Expected Behavior:
The compiler should gracefully reject the code and emit a syntax or type error
regarding the invalid use of auto in the function prototype without a valid
deduction context, rather than crashing in the backend.

Reply via email to