https://gcc.gnu.org/g:08a01465d802616256c5dff8d04e16fcb4a3d831
commit r17-450-g08a01465d802616256c5dff8d04e16fcb4a3d831 Author: Marek Polacek <[email protected]> Date: Thu May 7 15:39:09 2026 -0400 c++: refine decl_defined_p 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. Reviewed-by: Jason Merrill <[email protected]> Diff: --- gcc/cp/decl2.cc | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/gcc/cp/decl2.cc b/gcc/cp/decl2.cc index a0bc57d4a06d..785f669348ef 100644 --- a/gcc/cp/decl2.cc +++ b/gcc/cp/decl2.cc @@ -5324,7 +5324,13 @@ decl_defined_p (tree decl) else { gcc_assert (VAR_P (decl)); - return !DECL_EXTERNAL (decl); + return (!DECL_EXTERNAL (decl) + /* 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. */ + || (DECL_INITIAL (decl) && !DECL_IN_AGGR_P (decl))); } }
