[Bug c++/92722] gcc considers "padding" byte of empty lambda to be uninitialized

msebor at gcc dot gnu.org gcc-bugzilla@gcc.gnu.org
Wed Apr 7 19:42:25 GMT 2021


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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
         Resolution|---                         |WONTFIX
             Status|NEW                         |RESOLVED
                 CC|                            |msebor at gcc dot gnu.org

--- Comment #4 from Martin Sebor <msebor at gcc dot gnu.org> ---
The IL the warning works with is below.  It shows an unconditional read of the
uninitialized member array bytes so the warning behaves correctly.  The warning
does have suppression logic for empty types, including lambdas, but the test
case copies the representation bytes of the object directly and there's nothing
to avoid the warning then.  So I don't think there's anything for us to do
here.

In static member function ‘static void
noncopyable_function::trivial_direct_move(noncopyable_function*,
noncopyable_function*) [with int N = 1]’,
    inlined from
‘noncopyable_function::noncopyable_function(noncopyable_function&&)’ at
pr92722.C:32:31,
    inlined from ‘int main()’ at pr92722.C:43:40:
pr92722.C:22:43: warning: ‘a.noncopyable_function::direct[0]’ is used
uninitialized [-Wuninitialized]
   22 |             to->direct[i] = from->direct[i];
      |                             ~~~~~~~~~~~~~~^
pr92722.C: In function ‘int main()’:
pr92722.C:42:26: note: ‘a’ declared here
   42 |     noncopyable_function a([] {});
      |                          ^
int main ()
{
  struct noncopyable_function b;
  struct noncopyable_function a;
  char _2;

  <bb 2> [local count: 1073741824]:
  # .MEM_7 = VDEF <.MEM_1(D)>
  a ={v} {CLOBBER};
  # .MEM_8 = VDEF <.MEM_7>
  b ={v} {CLOBBER};
  # VUSE <.MEM_8>
  _2 = a.direct[0];           <<< a.direct[0] is uninitialized
  # .MEM_9 = VDEF <.MEM_8>
  b.direct[0] = _2;           <<< -Wuninitialized
  # .MEM_3 = VDEF <.MEM_9>
  noncopyable_function::~noncopyable_function (&b);
  # .MEM_4 = VDEF <.MEM_3>
  noncopyable_function::~noncopyable_function (&a);
  # .MEM_5 = VDEF <.MEM_4>
  a ={v} {CLOBBER};
  # .MEM_6 = VDEF <.MEM_5>
  b ={v} {CLOBBER};
  # VUSE <.MEM_6>
  return 0;

}


More information about the Gcc-bugs mailing list