Noticed ICE on r14-2233-gfca6d9c12f5bf0 when was building json-3.11.2 package. Extracted reproducer: // $ cat bug.cpp template <typename, typename> struct adl_serializer; template <template <typename, typename> class = adl_serializer> class basic_json; template <typename> struct json_pointer { template <template <typename, typename> class> friend class basic_json; }; template <template <typename, typename> class> struct basic_json { using json_pointer = json_pointer<int>; }; basic_json<>::json_pointer __trans_tmp_1_DOCTEST_ANON_FUNC_2() { json_pointer<basic_json<>> ptr_j; } $ g++ -c bug.cpp bug.cpp:10:9: warning: declaration of 'using basic_json< <template-parameter-1-1> >::json_pointer = struct json_pointer<int>' changes meaning of 'json_pointer' [-Wchanges-meaning] 10 | using json_pointer = json_pointer<int>; | ^~~~~~~~~~~~ bug.cpp:10:24: note: used here to mean 'struct json_pointer<int>' 10 | using json_pointer = json_pointer<int>; | ^~~~~~~~~~~~~~~~~ bug.cpp:6:28: note: declared here 6 | template <typename> struct json_pointer { | ^~~~~~~~~~~~ bug.cpp: In instantiation of 'struct json_pointer<basic_json<> >': bug.cpp:13:30: required from here bug.cpp:7:63: internal compiler error: in redeclare_class_template, at cp/pt.cc:6391 7 | template <template <typename, typename> class> friend class basic_json; | ^~~~~~~~~~ 0x708b6c redeclare_class_template(tree_node*, tree_node*, tree_node*) ../../source/gcc/cp/pt.cc:6391 0x8fe749 tsubst_friend_class ../../source/gcc/cp/pt.cc:11590 0x8fe749 instantiate_class_template(tree_node*) ../../source/gcc/cp/pt.cc:12446 0x9398ed complete_type(tree_node*) ../../source/gcc/cp/typeck.cc:138 0x7c49e2 start_decl_1(tree_node*, bool) ../../source/gcc/cp/decl.cc:5980 0x7de3e9 start_decl_1(tree_node*, bool) ../../source/gcc/cp/decl.cc:5946 0x7de3e9 start_decl(cp_declarator const*, cp_decl_specifier_seq*, int, tree_node*, tree_node*, tree_node**) ../../source/gcc/cp/decl.cc:5946 0x8b70b7 cp_parser_init_declarator ../../source/gcc/cp/parser.cc:22951 0x88f971 cp_parser_simple_declaration ../../source/gcc/cp/parser.cc:15435 0x891520 cp_parser_declaration_statement ../../source/gcc/cp/parser.cc:14516 0x891c39 cp_parser_statement ../../source/gcc/cp/parser.cc:12574 0x892d6d cp_parser_statement_seq_opt ../../source/gcc/cp/parser.cc:13000 0x892e0f cp_parser_compound_statement ../../source/gcc/cp/parser.cc:12952 0x8b5881 cp_parser_function_body ../../source/gcc/cp/parser.cc:25372 0x8b5881 cp_parser_ctor_initializer_opt_and_function_body ../../source/gcc/cp/parser.cc:25423 0x8b6a4e cp_parser_function_definition_after_declarator ../../source/gcc/cp/parser.cc:32058 0x8b7dcc cp_parser_function_definition_from_specifiers_and_declarator ../../source/gcc/cp/parser.cc:31975 0x8b7dcc cp_parser_init_declarator ../../source/gcc/cp/parser.cc:22831 0x88f971 cp_parser_simple_declaration ../../source/gcc/cp/parser.cc:15435 0x8c1ddb cp_parser_declaration ../../source/gcc/cp/parser.cc:15121 $ g++ -v Using built-in specs. COLLECT_GCC=/<<NIX>>/gcc-14.0.0/bin/g++ COLLECT_LTO_WRAPPER=/<<NIX>>/gcc-14.0.0/libexec/gcc/x86_64-unknown-linux-gnu/14.0.0/lto-wrapper Target: x86_64-unknown-linux-gnu Configured with: Thread model: posix Supported LTO compression algorithms: zlib gcc version 14.0.0 99999999 (experimental) (GCC)
Created attachment 55452 [details] bug.cpp.orig.xz In case I reduced the file incorrectly attaching bug.cpp.orig.xz which should build with both gcc-13 and gcc-14.
Re-reducing it so it is warning free as the original was warning free.
Better reduced testcase: ``` template <typename> class v {}; template <template <typename> class a = v> class basic_json {}; template <typename t> struct json_pointer { template <template <typename> class a> friend class basic_json; using type = t; }; json_pointer<int>::type t; json_pointer<basic_json<>>::type t1; ```
I see something similar when building dlib: /home/dcb38/rpmbuild/BUILD/dlib-65bce59a1512cf222dec01d3e0f29b612dd181f5/dlib/../dlib/dnn/core.h:799:22: internal compiler error: in redeclare_class_template, at cp/pt.cc:6391
The compiler seems to break as follows: /home/dcb38/gcc/results.20230701/bin/gcc /home/dcb38/gcc/results.20230703.asan.ubsan/bin/gcc /home/dcb38/rpmbuild/BUILD/dlib-65bce59a1512cf222dec01d3e0f29b612dd181f5/dlib/../dlib/dnn/core.h:799:22: internal compiler error: in redeclare_class_template, at cp/pt.cc:6391 $ /home/dcb38/gcc/results.20230701/bin/gcc -v 2>&1 | grep exp gcc version 14.0.0 20230630 (experimental) (c3c0ba5436170e01) $ /home/dcb38/gcc/results.20230703.asan.ubsan/bin/gcc -v 2>&1 | grep exp gcc version 14.0.0 20230703 (experimental) (9a856f67ee2f13ea) $ git log c3c0ba5436170e01..9a856f67ee2f13ea | grep -c "^commit" 45 $
The only C++ related commit in that range is: commit db38b285ba61c5b888adc0d117177bfd774c1153 Author: Patrick Palka <ppalka@redhat.com> Date: Fri Jun 30 15:05:22 2023 -0400 c++: fix up caching of level lowered ttps
I have tried to start a git bisect and the current range is g:f3d87219dd502d5c .. g:9757e4440bd8755d. This is 15 commits.
(In reply to David Binderman from comment #7) > I have tried to start a git bisect and the current range is > g:f3d87219dd502d5c .. g:9757e4440bd8755d. > > This is 15 commits. I messed this one up and started again. As expected, Patrick's commit seems to be the one: $ git bisect bad db38b285ba61c5b8 db38b285ba61c5b888adc0d117177bfd774c1153 is the first bad commit commit db38b285ba61c5b888adc0d117177bfd774c1153 Author: Patrick Palka <ppalka@redhat.com> Date: Fri Jun 30 15:05:22 2023 -0400 c++: fix up caching of level lowered ttps
Simplified: template<template<class, class> class> class basic_json; template<class> struct json_pointer { template<template<class, class> class> friend class basic_json; }; template struct json_pointer<int>; template struct json_pointer<char>; template struct json_pointer<long>;
The master branch has been updated by Patrick Palka <ppalka@gcc.gnu.org>: https://gcc.gnu.org/g:2c60368ab5706a870a1a3be190acc4d673672c30 commit r14-2421-g2c60368ab5706a870a1a3be190acc4d673672c30 Author: Patrick Palka <ppalka@redhat.com> Date: Mon Jul 10 10:59:40 2023 -0400 c++: redeclare_class_template and ttps [PR110523] Now that we cache level-lowered ttps we can end up processing the same ttp multiple times via (multiple calls to) redeclare_class_template, so we can't assume a ttp's DECL_CONTEXT is initially empty. PR c++/110523 gcc/cp/ChangeLog: * pt.cc (redeclare_class_template): Relax the ttp DECL_CONTEXT assert, and downgrade it to a checking assert. gcc/testsuite/ChangeLog: * g++.dg/template/ttp37.C: New test.
Fixed.
I confirm ICE gone away for json-3.11.2. json-3.11.2 still odes not compile same as in https://gcc.gnu.org/PR110580