https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114114
Bug ID: 114114 Summary: Internal compiler error on function-local conditional noexcept Product: gcc Version: 13.2.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: yves.bailly at hexagon dot com Target Milestone: --- Created attachment 57542 --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=57542&action=edit Preprocessed file from -save-temps Tested on: - Ubuntu 22.04 with distribution's GCC 11.4.0 - Ubuntu 22.04 with "home-build" GCC 13.2.0 - Ubuntu 23.10 with distribution's GCC 13.2.0 - Godbolt's compiler explorer with GCC x86-64 "trunk" The following code causes an internal compiler error on (1): --8<-----8<-----8<-----8<-----8<-----8<-----8<-----8<--- #include <iostream> enum class YesNo: bool { Yes, No }; template <typename E> [[nodiscard]] constexpr bool isYes(const E e) noexcept { return e == E::Yes; } template<YesNo yes_or_no> constexpr void test() { [[maybe_unused]] constexpr bool is_yes = isYes(yes_or_no); // (1) struct S { #if true // (2) constexpr S() noexcept(is_yes) { std::cout << "boo\n"; } // The following compiles fine: #else constexpr S() noexcept(yes_or_no == YesNo::Yes) { std::cout << "boo ok\n"; } #endif }; S s; } int main() { test<YesNo::Yes>(); } --8<-----8<-----8<-----8<-----8<-----8<-----8<-----8<--- Changing the "true" to "false" on (2) makes the code compile, link and run fine. Note: this code is accepted by Clang and MSVC. Output of gcc -v: Using built-in specs. COLLECT_GCC=/home/ybailly/gcc13/bin/g++ COLLECT_LTO_WRAPPER=/home/ybailly/gcc13/libexec/gcc/x86_64-pc-linux-gnu/13.2.0/lto-wrapper Target: x86_64-pc-linux-gnu Configured with: ../gcc-13.2.0/configure --prefix=/home/ybailly/gcc13 --enable-languages=c,c++,fortran --disable-multilib Thread model: posix Supported LTO compression algorithms: zlib zstd gcc version 13.2.0 (GCC) Output of "~/gcc13/bin/g++ -o test_gcc.x -std=c++20 test_gcc.cpp": test_gcc.cpp: In instantiation of ‘constexpr test()::S::S() [with YesNo yes_or_no = YesNo::Yes]’: test_gcc.cpp:16:19: required from ‘constexpr test()::S::S() [with YesNo yes_or_no = YesNo::Yes]’ test_gcc.cpp:24:5: required from ‘constexpr void test() [with YesNo yes_or_no = YesNo::Yes]’ test_gcc.cpp:31:21: required from here test_gcc.cpp:11:37: internal compiler error: Segmentation fault 11 | [[maybe_unused]] constexpr bool is_yes = isYes(yes_or_no); // (1) | ^~~~~~ 0xe013bf crash_signal ../../gcc-13.2.0/gcc/toplev.cc:314 0x7f673d7e851f ??? ./signal/../sysdeps/unix/sysv/linux/x86_64/libc_sigaction.c:0 0x88089e hash_table<hash_map<tree_node*, tree_node*, simple_hashmap_traits<default_hash_traits<tree_node*>, tree_node*> >::hash_entry, false, xcallocator>::find_slot_with_hash(tree_node* const&, unsigned int, insert_option) ../../gcc-13.2.0/gcc/hash-table.h:1039 0x88089e hash_map<tree_node*, tree_node*, simple_hashmap_traits<default_hash_traits<tree_node*>, tree_node*> >::put(tree_node* const&, tree_node* const&) ../../gcc-13.2.0/gcc/hash-map.h:170 0x88089e register_local_specialization(tree_node*, tree_node*) ../../gcc-13.2.0/gcc/cp/pt.cc:1970 0x896009 tsubst_decl ../../gcc-13.2.0/gcc/cp/pt.cc:15446 0x885904 tsubst_copy ../../gcc-13.2.0/gcc/cp/pt.cc:17417 0x886588 tsubst_copy_and_build(tree_node*, tree_node*, int, tree_node*) ../../gcc-13.2.0/gcc/cp/pt.cc:21676 0x889bed maybe_instantiate_noexcept(tree_node*, int) ../../gcc-13.2.0/gcc/cp/pt.cc:26754 0x88ddb2 regenerate_decl_from_template ../../gcc-13.2.0/gcc/cp/pt.cc:26553 0x88ddb2 instantiate_body ../../gcc-13.2.0/gcc/cp/pt.cc:26865 0x88e678 instantiate_decl(tree_node*, bool, bool) ../../gcc-13.2.0/gcc/cp/pt.cc:27217 0x897f22 tsubst_expr(tree_node*, tree_node*, int, tree_node*) ../../gcc-13.2.0/gcc/cp/pt.cc:19397 0x898431 tsubst_expr(tree_node*, tree_node*, int, tree_node*) ../../gcc-13.2.0/gcc/cp/pt.cc:18844 0x898431 tsubst_expr(tree_node*, tree_node*, int, tree_node*) ../../gcc-13.2.0/gcc/cp/pt.cc:18858 0x898265 tsubst_expr(tree_node*, tree_node*, int, tree_node*) ../../gcc-13.2.0/gcc/cp/pt.cc:18844 0x898265 tsubst_expr(tree_node*, tree_node*, int, tree_node*) ../../gcc-13.2.0/gcc/cp/pt.cc:19238 0x88de06 tsubst_expr(tree_node*, tree_node*, int, tree_node*) ../../gcc-13.2.0/gcc/cp/pt.cc:26930 0x88de06 instantiate_body ../../gcc-13.2.0/gcc/cp/pt.cc:26930 0x88e678 instantiate_decl(tree_node*, bool, bool) ../../gcc-13.2.0/gcc/cp/pt.cc:27217 Preprocessed file attached, greatly reduced by removing <iostream> - the same error appears without it. Regards,