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

            Bug ID: 112766
           Summary: [14 regression] spurious -Wmaybe-uninitialized with
                    array new
           Product: gcc
           Version: 14.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: s...@li-snyder.org
  Target Milestone: ---

hi -

With a recent checkout of gcc14 (20231129), on a x86_64-pc-linux-gnu host,
the following source gives a bogus -Wmaybe-uninitialized warning
with -Wall:

--------------------------------------------------------------
void* operator new[](unsigned long, void* __p) ;

class Result
{
public:
  Result();
  ~Result();
};

void *foo(long nElements, void *p) {
  return p ? new((int*)p) Result[nElements] : new Result[nElements];
}
--------------------------------------------------------------


$ g++ -c -O1 -Wall x.cc
x.cc: In function ‘void* foo(long int, void*)’:
x.cc:11:67: warning: ‘nElements.6’ may be used uninitialized
[-Wmaybe-uninitialized]
   11 |   return p ? new((int*)p) Result[nElements] : new Result[nElements];
      |                                                                   ^
x.cc:11:58: note: ‘nElements.6’ was declared here
   11 |   return p ? new((int*)p) Result[nElements] : new Result[nElements];
      |                                                          ^~~~~~~~~

We get the same warning with -O2 and -O3, but not -O0.

This warning does not occur with gcc 13.2.1 20230728.

Reply via email to