https://gcc.gnu.org/bugzilla/show_bug.cgi?id=119525
Bug ID: 119525 Summary: ICE when using template alias parameter deduction on alias for std::variant Product: gcc Version: 15.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: whiteredredcat at gmail dot com Target Milestone: --- Created attachment 60911 --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=60911&action=edit the requested report generated with -freport-bug When compiling the code below in the file `test2.cpp` with the command `g++ --std=c++23 test2.cpp` the compiler suffers an internal compiler error. ``` #include <variant> template<typename T> using templated_varient = std::variant<T>; int main() { templated_varient meow = std::variant<int>(10); return 0; } // vim: ts=2 sw=2 ``` The compiler output to console is thus: ``` In file included from test2.cpp:1: /home/plum/patches/gcc-compile/built/include/c++/15.0.1/variant: In substitution of ‘template<class ... _Types> template<class _Tp, class> using std::variant<_Types>::__accepted_type = std::variant<_Types>::__to_type<((long unsigned int)__accepted_index<_Tp>)> [with _Tp = _Tp&&; <template-parameter-2-2> = typename std::enable_if<std::variant<T>::__not_self<_Tp&&>, void>::type; _Types = {T}]’: test2.cpp:7:47: required from here 7 | templated_varient meow = std::variant<int>(10); | ^ /home/plum/patches/gcc-compile/built/include/c++/15.0.1/variant:1462:43: internal compiler error: Segmentation fault 1462 | using __accepted_type = __to_type<__accepted_index<_Tp>>; | ^~~~~~~~~~~~~~~~~~~~ 0x294365f internal_error(char const*, ...) /home/plum/patches/gcc-compile/../gcc/gcc/diagnostic-global-context.cc:517 0x144d6af crash_signal /home/plum/patches/gcc-compile/../gcc/gcc/toplev.cc:322 0xd118f1 tsubst_expr(tree_node*, tree_node*, int, tree_node*) /home/plum/patches/gcc-compile/../gcc/gcc/cp/pt.cc:20558 0xd126e8 tsubst_expr(tree_node*, tree_node*, int, tree_node*) /home/plum/patches/gcc-compile/../gcc/gcc/cp/pt.cc:20655 0xd1772d tsubst_expr(tree_node*, tree_node*, int, tree_node*) /home/plum/patches/gcc-compile/../gcc/gcc/cp/pt.cc:13002 0xd1772d tsubst_template_arg(tree_node*, tree_node*, int, tree_node*) /home/plum/patches/gcc-compile/../gcc/gcc/cp/pt.cc:13013 0xd1772d tsubst_template_arg(tree_node*, tree_node*, int, tree_node*) /home/plum/patches/gcc-compile/../gcc/gcc/cp/pt.cc:13001 0xd271f9 tsubst_template_args(tree_node*, tree_node*, int, tree_node*) /home/plum/patches/gcc-compile/../gcc/gcc/cp/pt.cc:14230 0xd274f2 tsubst_template_args(tree_node*, tree_node*, int, tree_node*) /home/plum/patches/gcc-compile/../gcc/gcc/cp/pt.cc:14212 0xd0b8b2 tsubst(tree_node*, tree_node*, int, tree_node*) /home/plum/patches/gcc-compile/../gcc/gcc/cp/pt.cc:16836 0xd0c268 tsubst(tree_node*, tree_node*, int, tree_node*) /home/plum/patches/gcc-compile/../gcc/gcc/cp/pt.cc:16446 0xd1f33a tsubst_decl /home/plum/patches/gcc-compile/../gcc/gcc/cp/pt.cc:15772 0xd2c0bd instantiate_template(tree_node*, tree_node*, int) /home/plum/patches/gcc-compile/../gcc/gcc/cp/pt.cc:22700 0xd2c7a3 instantiate_alias_template /home/plum/patches/gcc-compile/../gcc/gcc/cp/pt.cc:22798 0xd0c2a0 instantiate_alias_template /home/plum/patches/gcc-compile/../gcc/gcc/cp/pt.cc:22776 0xd0c2a0 tsubst(tree_node*, tree_node*, int, tree_node*) /home/plum/patches/gcc-compile/../gcc/gcc/cp/pt.cc:16447 0xd1873f rewrite_tparm_list /home/plum/patches/gcc-compile/../gcc/gcc/cp/pt.cc:30415 0xd3545b alias_ctad_tweaks /home/plum/patches/gcc-compile/../gcc/gcc/cp/pt.cc:30944 0xcf5801 deduction_guides_for /home/plum/patches/gcc-compile/../gcc/gcc/cp/pt.cc:31302 0xcf5eaf do_class_deduction /home/plum/patches/gcc-compile/../gcc/gcc/cp/pt.cc:31472 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. ``` Attached is the preprocessed source as requested. My compiled gcc version is `gcc (GCC) 15.0.1 20250326`. I previously reported this bug to the Arch Linux tracker as it also exists in gcc 14, see here for details: https://gitlab.archlinux.org/archlinux/packaging/packages/gcc/-/issues/22 There Toolybird independently confirms that this bug exists in GCC 15. As for duplicate bugs, the closest I found was https://gcc.gnu.org/bugzilla/show_bug.cgi?id=115412 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=86961 Though both of these have the templated using statement inside a struct and thus are potentially different. If I write templated_varient<int> meow = std::variant<int>(10);` instead, the file complies with no issues. `clang++ --std=c++23 test2.cpp` compiles the original buggy file with no complaints.