[Bug c++/94905] New: Bogus warning -Werror=maybe-uninitialized

2020-05-01 Thread bug-apl at gnu dot org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94905

Bug ID: 94905
   Summary: Bogus warning -Werror=maybe-uninitialized
   Product: gcc
   Version: 9.3.0
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: c++
  Assignee: unassigned at gcc dot gnu.org
  Reporter: bug-apl at gnu dot org
  Target Milestone: ---

Hi,

as of g++ 9.3.0 when building GNU APL, g++ emits bogus warnings of type
-Werror=maybe-uninitialized.

Apparently the compiler issues these warnings simply because it is lacking
enough context to really figure out what is happening (e.g. if the supposedly
missing initialization is happening in a different function).

An example is:

https://svn.savannah.gnu.org/viewvc/apl/trunk/src/Shape.hh?view=markup

Shape.hh:133:18: error: ‘shape_Z.Shape::rho[axis]’ may be used
uninitialized in this function [-Werror=maybe-uninitialized]
 if (rho[r])   { volume /= rho[r];  rho[r] = sh;  volume *=
rho[r]; }
 ~^

The line 133 is preceded by an assertion that verifies that rho[r] is
initialized. Apparently the compiler assumes that the initialization
of rho[r] on the right of = happens after the test of rho[r] on the left
of =. It completely ignores, however, the fact that rho[r] was simply
updated and was initialized already before the function (set_shape_item)
was called.

May I kindly request to move this kind of warnings away from -Wall to
-Wextra ?

According to "man g++":

  -Wall
   This enables all the warnings about constructions that some users
   consider questionable, and that are easy to avoid (or modify to
   prevent the warning), even in conjunction with macros.  This also

In the example above there is no "easy to avoid" way to fix the warning.

Kind regards,
Jürgen Sauermann
Maintainer of GNU APL

[Bug c++/94905] Bogus warning -Werror=maybe-uninitialized

2020-05-03 Thread bug-apl at gnu dot org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94905

--- Comment #2 from Dr. Jürgen Sauermann  ---
I checked different g++ versions; the problem occurs in versions 9, 10, and 11
of g++ but not in version 8.

I tried to shrink the code to the bare minimum but if I do so then the warning
is no longer emitted.

I noticed that the warning has become more verbose in g++ version 11.
Before version 11 the warning said (one example of many):


Shape.hh:133:18: error: ‘shape_Z.Shape::rho[axis]’ may be used
uninitialized in this function [-Werror=maybe-uninitialized]
 if (rho[r])   { volume /= rho[r];  rho[r] = sh;  volume
*= rho[r]; }
  ~^

In version g++ 11 it now says:


Shape.hh: In member function ‘virtual Token Bif_F12_FORMAT::eval_B(Value_P)’:
Shape.hh:133:18: error: ‘shape_Z.Shape::rho[]’ may be used
uninitialized in this function [-Werror=maybe-uninitialized]
  133 | if (rho[r])   { volume /= rho[r];  rho[r] = sh;  volume *=
rho[r]; }
  | ~^


The  in shape_Z.Shape::rho[] above is the function argument
'axis' of the function set_shape_item(axis, length) inside which the warning is
being issued.

This suggests that the warning is issued whenever the compiler is unable to
statically determine if some function argument (the vector index 'axiss' in
this case) is inside or outside the initialized region of a vector.

This seems to be overly picky; I would normally assume that the data members of
a class are always initialized. If not then the constructor and not any member
function should emit a warning.

Thanks for your attention and for gcc/g++
Jürgen Sauermann

[Bug c++/94905] Bogus warning -Werror=maybe-uninitialized

2020-05-03 Thread bug-apl at gnu dot org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94905

--- Comment #4 from Dr. Jürgen Sauermann  ---
Created attachment 48431
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=48431&action=edit
preprocessed apl-Bif_F12_FORMAT.cc, gzip'ed

preprocessed source file apl-Bif_F12_FORMAT.cc

[Bug c++/94905] Bogus warning -Werror=maybe-uninitialized

2020-05-03 Thread bug-apl at gnu dot org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94905

--- Comment #5 from Dr. Jürgen Sauermann  ---
Hi,

above is one preprocessed source file for which the warning has occurred. g++
version was 11.0.0 (latest from github). 

Compiled with:

g++ -E -DHAVE_CONFIG_H -I. -I..-Wall -I sql -Werror -I/usr/include
-I/usr/include/postgresql   -rdynamic -g -O2 -MT apl-Bif_F12_FORMAT.o -MD -MP
-MF .deps/apl-Bif_F12_FORMAT.Tpo -c -o apl-Bif_F12_FORMAT.cxx


Interestingly, if I compile the file apl-Bif_F12_FORMAT.cxx separately (with
-Wall) then the warning does not show up.

Not sure how I can create a testcase file other than preprocessing or
minimizing it.