https://gcc.gnu.org/bugzilla/show_bug.cgi?id=127428
Bug ID: 127428
Summary: [C++26] ICE (segfault) in poplevel (decl.cc:783) with
lambda in contract precondition and deducing-this
template
Product: gcc
Version: 17.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: vincent.liu at arista dot com
Target Milestone: ---
There were bugs with similar-sounding repro conditions but unlike the others,
this one segfaults with a different stack trace near the crash. So I'm inclined
to believe it's a different issue.
Godbolt link: https://godbolt.org/z/4E74P55fq
Minimal repro (works on gcc 16.1 to trunk):
`g++ -std=c++26 file.cpp`
(crashes with and without -fcontracts -Wall -Wextra -fno-strict-aliasing
-fwrapv)
file.cpp
```
// GCC 16.2.0 ICE: Segfault in poplevel() (cp/decl.cc:783)
// Flags: -std=c++26 -fcontracts -fcontract-evaluation-semantic=observe
-freflection
#include <string_view>
// 1. A struct with a lambda-in-precondition containing `if consteval`
struct A {
constexpr A(std::string_view s)
pre([&]() consteval {
if consteval { return true; }
else { return !s.empty(); }
}());
};
// 2. A deducing-this template, declared BEFORE A's out-of-line constructor
struct B {
int val;
template <typename Self>
constexpr auto& get(this const Self& self) { return self.val; }
};
// 3. Out-of-line constructor definition of A (triggers the crash)
constexpr A::A(std::string_view) {}
```