On 5/7/26 6:06 PM, Marek Polacek wrote:
Bootstrapped/regtested on x86_64-pc-linux-gnu, ok for trunk?-- >8 -- As discussed in the 124770 patch. This makes decl_defined_p correct for more cases. gcc/cp/ChangeLog: * decl2.cc (decl_defined_p): Also return true if DECL_INITIAL and !DECL_IN_AGGR_P is true for a VAR_DECL. --- gcc/cp/decl2.cc | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/gcc/cp/decl2.cc b/gcc/cp/decl2.cc index a0bc57d4a06..d45d7de4f59 100644 --- a/gcc/cp/decl2.cc +++ b/gcc/cp/decl2.cc @@ -5324,7 +5324,9 @@ decl_defined_p (tree decl) else { gcc_assert (VAR_P (decl)); - return !DECL_EXTERNAL (decl); + return (!DECL_EXTERNAL (decl) + /* extern constexpr inline T foo{}; is a definition. */
I'd go with something more like "An initialized variable is defined even if we've decided not to emit it, unless it's initialized within the class and not inline. Note that finish_static_member_decl doesn't set DECL_IN_AGGR_P for inline variables, so we don't need to check DECL_INLINE_VAR_P here."
OK with that change.
+ || (DECL_INITIAL (decl) && !DECL_IN_AGGR_P (decl)));
