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

--- Comment #7 from Jonathan Wakely <redi at gcc dot gnu.org> ---
(In reply to Žarko Asen from comment #5)
> in my case (C++ 20) -Wunitialized was not enabled by -Wall therefore a
> critical bug slip through:
> 
> const uint32_t x = x + 1; // where is a novel variable in the local and
> global scope
> 
> This should have been caught by -Wall and it wasn't. G++14.2.0 C++20 -Wall
> -pedantic -Werror

You haven't shown a testcase where you don't get that warning.

As I said by email, there's no warning for a global variable because it's
zero-initialized (although Clang still warns and I think that would be useful
for GCC too). At local scope GCC does warn e.g.


#include <stdint.h>

int f()
{
  const uint32_t x1 = x1 + 1;
  return 0;
}

self.cc: In function ‘f’:
self.cc:5:18: warning: ‘x1’ is used uninitialized [-Wuninitialized]
    5 |   const uint32_t x1 = x1 + 1;
      |                  ^~
self.cc:5:18: note: ‘x1’ was declared here
    5 |   const uint32_t x1 = x1 + 1;
      |                  ^~

Reply via email to