]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
c++: refine decl_defined_p
authorMarek Polacek <polacek@redhat.com>
Thu, 7 May 2026 19:39:09 +0000 (15:39 -0400)
committerMarek Polacek <polacek@redhat.com>
Mon, 11 May 2026 17:57:54 +0000 (13:57 -0400)
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 <jason@redhat.com>
gcc/cp/decl2.cc

index a0bc57d4a06d8c8581e41a8052bb5098afdfbb05..785f669348ef4ab82b914623f578ce8fce645c9d 100644 (file)
@@ -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)));
     }
 }