public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/103159] New: -Wuninitialized should not depend on optimization level
@ 2021-11-09 14:18 mathieu.malaterre at gmail dot com
  2021-11-09 14:22 ` [Bug c++/103159] " mathieu.malaterre at gmail dot com
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: mathieu.malaterre at gmail dot com @ 2021-11-09 14:18 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 103159
           Summary: -Wuninitialized should not depend on optimization
                    level
           Product: gcc
           Version: 10.2.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: mathieu.malaterre at gmail dot com
  Target Milestone: ---

Consider the following:

```
% cat undef.cxx
#include <iostream>

class C
{
    int I;
public:
    int getI() { return I; }
};

int main()
{
    C c;
    std::cout << c.getI() << std::endl;

    return 0;
}
```

It is counter-intuitive to explicitely use -O2 to have a warning reported.
Compare the output of:

```
% g++ -o undef -Wuninitialized undef.cxx && ./undef
0
```

While:

```
% g++ -O2 -o undef -Wuninitialized undef.cxx && ./undef
undef.cxx: In function ‘int main()’:
undef.cxx:7:25: warning: ‘c.C::I’ is used uninitialized in this function
[-Wuninitialized]
    7 |     int getI() { return I; }
      |                         ^
0
```

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [Bug c++/103159] -Wuninitialized should not depend on optimization level
  2021-11-09 14:18 [Bug c++/103159] New: -Wuninitialized should not depend on optimization level mathieu.malaterre at gmail dot com
@ 2021-11-09 14:22 ` mathieu.malaterre at gmail dot com
  2021-11-09 14:38 ` rguenth at gcc dot gnu.org
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: mathieu.malaterre at gmail dot com @ 2021-11-09 14:22 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #1 from Mathieu Malaterre <mathieu.malaterre at gmail dot com> ---
Just to be sure, here is the actual command I had been starring at for a while:

```
% g++ -o undef -fsanitize=undefined -Wuninitialized undef.cxx && ./undef
21845
```

Maybe I got confused with `-fsanitize=undefined` and (maybe?) g++ behavior at
default -O0 really does initialize all members in the class...

In any case my usual rule of thumb is to remove optimization flag when doing
debug/high warning level compilation.

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [Bug c++/103159] -Wuninitialized should not depend on optimization level
  2021-11-09 14:18 [Bug c++/103159] New: -Wuninitialized should not depend on optimization level mathieu.malaterre at gmail dot com
  2021-11-09 14:22 ` [Bug c++/103159] " mathieu.malaterre at gmail dot com
@ 2021-11-09 14:38 ` rguenth at gcc dot gnu.org
  2021-11-09 14:40 ` mathieu.malaterre at gmail dot com
  2021-11-09 14:42 ` [Bug c++/103159] Some -Wuninitialized warnings still depend on optimization level - mathieu.malaterre at gmail dot com
  3 siblings, 0 replies; 5+ messages in thread
From: rguenth at gcc dot gnu.org @ 2021-11-09 14:38 UTC (permalink / raw)
  To: gcc-bugs

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

Richard Biener <rguenth at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Blocks|                            |24639
            Summary|Some -Wuninitialized        |-Wuninitialized should not
                   |warning still depend on     |depend on optimization
                   |optimization level          |level

--- Comment #2 from Richard Biener <rguenth at gcc dot gnu.org> ---
I'm sure there is a duplicate request.


Referenced Bugs:

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=24639
[Bug 24639] [meta-bug] bug to track all Wuninitialized issues

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [Bug c++/103159] -Wuninitialized should not depend on optimization level
  2021-11-09 14:18 [Bug c++/103159] New: -Wuninitialized should not depend on optimization level mathieu.malaterre at gmail dot com
  2021-11-09 14:22 ` [Bug c++/103159] " mathieu.malaterre at gmail dot com
  2021-11-09 14:38 ` rguenth at gcc dot gnu.org
@ 2021-11-09 14:40 ` mathieu.malaterre at gmail dot com
  2021-11-09 14:42 ` [Bug c++/103159] Some -Wuninitialized warnings still depend on optimization level - mathieu.malaterre at gmail dot com
  3 siblings, 0 replies; 5+ messages in thread
From: mathieu.malaterre at gmail dot com @ 2021-11-09 14:40 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #3 from Mathieu Malaterre <mathieu.malaterre at gmail dot com> ---
Please note that the documentation currently does not detail the need/impact of
optimization for this flag:

* https://gcc.gnu.org/onlinedocs/gcc/Warning-Options.html#index-Wuninitialized

Maybe just updating the documentation would be enough. Thanks for
consideration.

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [Bug c++/103159] Some -Wuninitialized warnings still depend on optimization level -
  2021-11-09 14:18 [Bug c++/103159] New: -Wuninitialized should not depend on optimization level mathieu.malaterre at gmail dot com
                   ` (2 preceding siblings ...)
  2021-11-09 14:40 ` mathieu.malaterre at gmail dot com
@ 2021-11-09 14:42 ` mathieu.malaterre at gmail dot com
  3 siblings, 0 replies; 5+ messages in thread
From: mathieu.malaterre at gmail dot com @ 2021-11-09 14:42 UTC (permalink / raw)
  To: gcc-bugs

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

Mathieu Malaterre <mathieu.malaterre at gmail dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
         Resolution|---                         |WORKSFORME

--- Comment #4 from Mathieu Malaterre <mathieu.malaterre at gmail dot com> ---
Nevermind, I managed to mis-read the documentation.

```
Because these warnings depend on optimization, the exact variables or elements
for which there are warnings depend on the precise optimization options and
version of GCC used.
```

Sorry for the noise.

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2021-11-09 14:42 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-11-09 14:18 [Bug c++/103159] New: -Wuninitialized should not depend on optimization level mathieu.malaterre at gmail dot com
2021-11-09 14:22 ` [Bug c++/103159] " mathieu.malaterre at gmail dot com
2021-11-09 14:38 ` rguenth at gcc dot gnu.org
2021-11-09 14:40 ` mathieu.malaterre at gmail dot com
2021-11-09 14:42 ` [Bug c++/103159] Some -Wuninitialized warnings still depend on optimization level - mathieu.malaterre at gmail dot com

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).