On Tue, Sep 22, 2026 at 11:51:07AM -0400, Jason Merrill wrote: > > As the following testcase shows, error_mark_node can appear anywhere > > in the ctors, and with the asserts we ICE on those during error > > recovery. The following patch just returns boolean_false_node > > in those cases, it doesn't really matter what exactly we return > > as long as we do't crash and ideally have some consistency. > > Why not return error_mark_node as usual?
That works too, just an extra error in the testcase, but perhaps it is better. 2026-09-22 Jakub Jelinek <[email protected]> PR c++/127506 * constexpr.cc (is_within_lifetime): When val is error_mark_node, return it. * g++.dg/cpp26/within-lifetime13.C: New test. --- a/gcc/cp/constexpr.cc 2026-09-22 15:52:09.649180741 +0200 +++ b/gcc/cp/constexpr.cc 2026-09-22 18:01:05.311704203 +0200 @@ -2657,6 +2657,8 @@ is_within_lifetime (location_t loc, cons } else if (val == val_uninit) return boolean_false_node; + else if (val == error_mark_node) + return val; else { gcc_assert (TREE_CODE (val) == CONSTRUCTOR); @@ -2685,6 +2687,8 @@ is_within_lifetime (location_t loc, cons } if (val == val_zero_init || val == val_uninit) continue; + if (val == error_mark_node) + return val; gcc_assert (TREE_CODE (val) == CONSTRUCTOR); unsigned int j; tree field, value; @@ -2718,6 +2722,8 @@ is_within_lifetime (location_t loc, cons return t; if (val == val_zero_init || val == val_uninit) continue; + if (val == error_mark_node) + return val; if (TREE_CODE (val) == STRING_CST) return boolean_true_node; gcc_assert (TREE_CODE (val) == CONSTRUCTOR); --- a/gcc/testsuite/g++.dg/cpp26/within-lifetime13.C 2026-09-22 18:00:21.902510413 +0200 +++ b/gcc/testsuite/g++.dg/cpp26/within-lifetime13.C 2026-09-22 18:06:26.817455332 +0200 @@ -0,0 +1,20 @@ +// PR c++/127506 +// { dg-do compile { target c++20 } } + +namespace std { + template <class T> + consteval bool + is_within_lifetime (const T *p) noexcept + { + return __builtin_is_within_lifetime (p); + } +} + +struct S { char a; }; +constexpr S s = { int b; }; // { dg-error "expected" } + +bool +bar () +{ + return (!std::is_within_lifetime (&s.a)); // { dg-error "is not a constant expression" } +} Jakub
