https://gcc.gnu.org/bugzilla/show_bug.cgi?id=96295

Martin Sebor <msebor at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Target Milestone|---                         |11.0
            Summary|Wmaybe-uninitialized        |[11 Regression]
                   |warning for range operator  |-Wmaybe-uninitialized
                   |with empty range struct     |warning for range operator
                   |                            |with reference to an empty
                   |                            |struct
             Status|UNCONFIRMED                 |ASSIGNED
     Ever confirmed|0                           |1
           Assignee|unassigned at gcc dot gnu.org      |msebor at gcc dot 
gnu.org
   Last reconfirmed|                            |2020-07-23
                 CC|                            |msebor at gcc dot gnu.org

--- Comment #1 from Martin Sebor <msebor at gcc dot gnu.org> ---
Confirmed.  The warning detects and avoids triggering for objects of empty
types but in the test case __for_range is a reference to such an object and the
logic doesn't consider those.  The tweak below makes the warning go away.  Let
me handle this.

diff --git a/gcc/tree-ssa-uninit.c b/gcc/tree-ssa-uninit.c
index 2f0ff724cde..fa88cad841c 100644
--- a/gcc/tree-ssa-uninit.c
+++ b/gcc/tree-ssa-uninit.c
@@ -401,6 +401,8 @@ maybe_warn_operand (ao_ref &ref, gimple *stmt, tree lhs,
tree rhs,
      The first_field() test is important for C++ where the predicate
      alone isn't always sufficient.  */
   tree rhstype = TREE_TYPE (rhs);
+  if (POINTER_TYPE_P (rhstype))
+    rhstype = TREE_TYPE (rhstype);
   if (TYPE_EMPTY_P (rhstype)
       || (RECORD_OR_UNION_TYPE_P (rhstype)
          && (!first_field (rhstype)

Reply via email to