Created attachment 48690 [details] C++ program to compile g++ -v Using built-in specs. COLLECT_GCC=g++ COLLECT_LTO_WRAPPER=d:/mingw/bin/../libexec/gcc/x86_64-w64-mingw32/10.1.0/lto-wrapper.exe Target: x86_64-w64-mingw32 Configured with: ../src/configure --enable-languages=c,c++ --build=x86_64-w64-mingw32 --host=x86_64-w64-mingw32 --target=x86_64-w64-mingw32 --disable-multilib --prefix=/d/temp/gcc/dest --with-sysroot=/d/temp/gcc/dest --disable-libstdcxx-pch --disable-libstdcxx-verbose --disable-nls --disable-shared --disable-win32-registry --with-architechture=native --enable-threads=posix --enable-libgomp Thread model: posix Supported LTO compression algorithms: zlib gcc version 10.1.0 (GCC) g++ -std=c++20 -Wall -Wextra test_cv.cpp test_cv.cpp: In function 'void testTimedIWait(bool, bool, Dur)': test_cv.cpp:464:28: internal compiler error: Segmentation fault 464 | enum class State { loop, ready, interrupted }; | ^~~~~ libbacktrace could not find executable to open Please submit a full bug report, with preprocessed source if appropriate. See <https://gcc.gnu.org/bugs/> for instructions.
Created attachment 48691 [details] Compile information .ii file compressed
Created attachment 48692 [details] assembler source
Confirmed, started with r10-4254-ge0d91792eec490d1. Reduced test-case: $ cat pr95560.ii template <typename> void fn1() { bool ready; enum class State { ready }; } $ g++ -c -std=c++2a pr95560.ii pr95560.ii: In function ‘void fn1()’: pr95560.ii:3:22: internal compiler error: in comptypes, at cp/typeck.c:1498 3 | enum class State { ready }; | ^~~~~ 0x6be442 comptypes(tree_node*, tree_node*, int) /home/marxin/Programming/gcc/gcc/cp/typeck.c:1498 0x9ab7ea check_local_shadow /home/marxin/Programming/gcc/gcc/cp/name-lookup.c:2765 0x9ab7ea do_pushdecl /home/marxin/Programming/gcc/gcc/cp/name-lookup.c:3112 0x9ac140 pushdecl(tree_node*, bool) /home/marxin/Programming/gcc/gcc/cp/name-lookup.c:3177 0x93c722 build_enumerator(tree_node*, tree_node*, tree_node*, tree_node*, unsigned int) /home/marxin/Programming/gcc/gcc/cp/decl.c:15922 0x9cd7a7 cp_parser_enumerator_definition /home/marxin/Programming/gcc/gcc/cp/parser.c:19544 0x9cd7a7 cp_parser_enumerator_list /home/marxin/Programming/gcc/gcc/cp/parser.c:19473 0x9cd7a7 cp_parser_enum_specifier /home/marxin/Programming/gcc/gcc/cp/parser.c:19404 0x9cd7a7 cp_parser_type_specifier /home/marxin/Programming/gcc/gcc/cp/parser.c:17734 0x9cdd62 cp_parser_decl_specifier_seq /home/marxin/Programming/gcc/gcc/cp/parser.c:14410 0x9ce941 cp_parser_simple_declaration /home/marxin/Programming/gcc/gcc/cp/parser.c:13664 0x9d07ea cp_parser_declaration_statement /home/marxin/Programming/gcc/gcc/cp/parser.c:13217 0x9d146a cp_parser_statement /home/marxin/Programming/gcc/gcc/cp/parser.c:11523 0x9d2398 cp_parser_statement_seq_opt /home/marxin/Programming/gcc/gcc/cp/parser.c:11889 0x9d2478 cp_parser_compound_statement /home/marxin/Programming/gcc/gcc/cp/parser.c:11839 0x9e9a65 cp_parser_function_body /home/marxin/Programming/gcc/gcc/cp/parser.c:23110 0x9e9a65 cp_parser_ctor_initializer_opt_and_function_body /home/marxin/Programming/gcc/gcc/cp/parser.c:23161 0x9ecd9d cp_parser_function_definition_after_declarator /home/marxin/Programming/gcc/gcc/cp/parser.c:29057 0x9edd89 cp_parser_function_definition_from_specifiers_and_declarator /home/marxin/Programming/gcc/gcc/cp/parser.c:28973 0x9edd89 cp_parser_init_declarator /home/marxin/Programming/gcc/gcc/cp/parser.c:20721 Please submit a full bug report, with preprocessed source if appropriate. Please include the complete backtrace with any bug report. See <https://gcc.gnu.org/bugs/> for instructions.
don't know if it helps, but with -Wshadow=compatible-local the regression begins probably earlier.
You are right, with: g++ pr95560.ii -std=c++17 -c -Wshadow=compatible-local it started with r7-4206-g84ff4775d41b716c.
We have a CONST_DECL with null type -- it's the case when the underlying type is not fixed, and finish_enum_value_list hasn't yet run. A stopgap fix would be --- a/gcc/cp/name-lookup.c +++ b/gcc/cp/name-lookup.c @@ -2762,7 +2762,9 @@ check_local_shadow (tree decl) enum opt_code warning_code; if (warn_shadow) warning_code = OPT_Wshadow; - else if (same_type_p (TREE_TYPE (old), TREE_TYPE (decl)) + else if ((TREE_TYPE (old) + && TREE_TYPE (decl) + && same_type_p (TREE_TYPE (old), TREE_TYPE (decl))) || TREE_CODE (decl) == TYPE_DECL || TREE_CODE (old) == TYPE_DECL || (!dependent_type_p (TREE_TYPE (decl))
The releases/gcc-10 branch has been updated by Marek Polacek <mpolacek@gcc.gnu.org>: https://gcc.gnu.org/g:23dd42562369911a92d7da045ebe2c03b286a769 commit r10-8281-g23dd42562369911a92d7da045ebe2c03b286a769 Author: Marek Polacek <polacek@redhat.com> Date: Thu Jun 11 16:35:33 2020 -0400 c++: Fix ICE in check_local_shadow with enum [PR95560] Another indication that perhaps this warning is emitted too early. We crash because same_type_p gets a null type: we have an enumerator without a fixed underlying type and finish_enum_value_list hasn't yet run. So check if the type is null before calling same_type_p. PR c++/95560 * name-lookup.c (check_local_shadow): Check if types are non-null before calling same_type_p. * g++.dg/warn/Wshadow-local-3.C: New test.
The releases/gcc-9 branch has been updated by Marek Polacek <mpolacek@gcc.gnu.org>: https://gcc.gnu.org/g:02f6c5b711b8188c3f49a79c730911b0bd216585 commit r9-8668-g02f6c5b711b8188c3f49a79c730911b0bd216585 Author: Marek Polacek <polacek@redhat.com> Date: Thu Jun 11 17:58:21 2020 -0400 c++: Fix ICE in check_local_shadow with enum [PR95560] Another indication that perhaps this warning is emitted too early. We crash because same_type_p gets a null type: we have an enumerator without a fixed underlying type and finish_enum_value_list hasn't yet run. So check if the type is null before calling same_type_p. PR c++/95560 * name-lookup.c (check_local_shadow): Check if types are non-null before calling same_type_p. * g++.dg/warn/Wshadow-compatible-local-3.C: New test.
Fixed.
Actually not on trunk yet.
The master branch has been updated by Marek Polacek <mpolacek@gcc.gnu.org>: https://gcc.gnu.org/g:2661635323bd44410f1a154683eccecd2c163b46 commit r11-1391-g2661635323bd44410f1a154683eccecd2c163b46 Author: Marek Polacek <polacek@redhat.com> Date: Tue Jun 16 13:02:23 2020 -0400 c++: Fix ICE in check_local_shadow with enum [PR95560] Another indication that perhaps this warning is emitted too early. We crash because same_type_p gets a null type: we have an enumerator without a fixed underlying type and finish_enum_value_list hasn't yet run. So check if the type is null before calling same_type_p. PR c++/95560 * name-lookup.c (check_local_shadow): Check if types are non-null before calling same_type_p. * g++.dg/warn/Wshadow-local-3.C: New test.