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

            Bug ID: 70246
           Summary: Spurious -Wmaybe-uninitialized warnings with -O1
           Product: gcc
           Version: 5.3.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: michael at jarvis dot net
  Target Milestone: ---

Created attachment 37980
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=37980&action=edit
Source code

The attached code is extracted from a larger code base that can view complex
vectors either normally or conjugated and do the right thing (either conj(rhs)
or not) when assigning values to memory.  Starting with gcc5 (I only have 5.3,
so I don't know about earlier 5.x versions), I am getting warnings related to
the possibly-conjugate assignment, although it took a while to track down,
since the warning shows up in a non-very helpful location.  I've extracted as
much as I could to get a minimal test case that reproduces the warning.

The compile command I'm using, and the warning I get are:

$ g++-5 -c -O1 -Wall -Iinclude gcc5_warning.cpp
gcc5_warning.cpp: In function ‘void TestVector()’:
gcc5_warning.cpp:61:6: warning: ‘rhs’ may be used uninitialized in this
function [-Wmaybe-uninitialized]
 void TestVector()
      ^

Compiler information:
$ g++-5 --version
g++-5 (GCC) 5.3.0
Copyright (C) 2015 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

System information:
$ uname -a
Darwin Fife 14.5.0 Darwin Kernel Version 14.5.0: Tue Sep  1 21:23:09 PDT 2015;
root:xnu-2782.50.1~1/RELEASE_X86_64 x86_64


Things I've discovered that remove the warning:
- Switch to using -O2 or -O3, or no -O flag at all.
- Switch line 13 to use `*_v = _c ? rhs : rhs;`, although interestingly,
changing it to `*_v = _c ? -rhs : rhs;` also gives the warning.
- Use the `*_v = _c ? -rhs : rhs;` variant, and also change CT on line 3 to be
double rather than complex<double>.
- Use literals for 100 and 50 rather than N and N/2
- Change line 63 to use `const int N = 100`, although in the larger code base
that this is extracted from, I did use `const int` and it gave the warning, so
maybe this is a red herring.

Reply via email to