https://gcc.gnu.org/bugzilla/show_bug.cgi?id=120684
Bug ID: 120684
Summary: bogus "error: destroying ‘<anonymous>’ outside its
lifetime" with constexpr dtor object inside
range-based for
Product: gcc
Version: 16.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: ppalka at gcc dot gnu.org
Target Milestone: ---
$ cat testcase.C
struct basic_string {
constexpr ~basic_string() {}
};
template <typename _Vp> struct lazy_split_view {
_Vp _M_base;
constexpr int* begin() { return nullptr; }
constexpr int* end() { return nullptr; }
};
constexpr void test_with_piping() {
basic_string input;
for (auto e : lazy_split_view(input))
;
}
constexpr bool main_test() {
test_with_piping();
test_with_piping();
return true;
}
static_assert(main_test());
$ g++ -std=c++20 testcase.C
testcase.C:20:24: error: non-constant condition for static assertion
20 | static_assert(main_test());
| ~~~~~~~~~^~
testcase.C:20:24: in ‘constexpr’ expansion of ‘main_test()’
testcase.C:17:19: in ‘constexpr’ expansion of ‘test_with_piping()’
testcase.C:12:38: error: destroying ‘<anonymous>’ outside its lifetime
12 | for (auto e : lazy_split_view(input))
| ^
testcase.C:12:38: note: declared here