public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "yves.bailly at hexagon dot com" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug c++/114114] New: Internal compiler error on function-local conditional noexcept
Date: Mon, 26 Feb 2024 13:46:52 +0000	[thread overview]
Message-ID: <bug-114114-4@http.gcc.gnu.org/bugzilla/> (raw)

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,

             reply	other threads:[~2024-02-26 13:46 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-02-26 13:46 yves.bailly at hexagon dot com [this message]
2024-02-26 16:58 ` [Bug c++/114114] [11/12/13/14 Regression] " pinskia at gcc dot gnu.org
2024-02-26 17:01 ` pinskia at gcc dot gnu.org
2024-02-26 19:01 ` ppalka at gcc dot gnu.org
2024-02-27  8:24 ` yves.bailly at hexagon dot com
2024-03-04 18:21 ` mpolacek at gcc dot gnu.org
2024-03-06 16:47 ` cvs-commit at gcc dot gnu.org
2024-03-06 16:48 ` [Bug c++/114114] [11/12/13 " mpolacek at gcc dot gnu.org

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=bug-114114-4@http.gcc.gnu.org/bugzilla/ \
    --to=gcc-bugzilla@gcc.gnu.org \
    --cc=gcc-bugs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).