public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/112766] New: [14 regression] spurious -Wmaybe-uninitialized with array new
@ 2023-11-29 16:54 sss@li-snyder.org
  2023-11-29 17:04 ` [Bug tree-optimization/112766] " mpolacek at gcc dot gnu.org
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: sss@li-snyder.org @ 2023-11-29 16:54 UTC (permalink / raw)
  To: gcc-bugs

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: sss@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.

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

end of thread, other threads:[~2023-11-30 12:35 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-11-29 16:54 [Bug c++/112766] New: [14 regression] spurious -Wmaybe-uninitialized with array new sss@li-snyder.org
2023-11-29 17:04 ` [Bug tree-optimization/112766] " mpolacek at gcc dot gnu.org
2023-11-30  9:01 ` [Bug tree-optimization/112766] [14 regression] spurious -Wmaybe-uninitialized with array new since r14-4089 rguenth at gcc dot gnu.org
2023-11-30  9:50 ` rguenth at gcc dot gnu.org
2023-11-30 12:35 ` cvs-commit at gcc dot gnu.org
2023-11-30 12:35 ` rguenth at gcc dot gnu.org

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).