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

            Bug ID: 91317
           Summary: [7/8/9/10 Regression] false-positive
                    maybe-uninitialized warning in destructor with
                    placement new
           Product: gcc
           Version: 8.3.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: martindorey at gmail dot com
  Target Milestone: ---

Sorry if this is already raised somewhere.  I did try to search various ways.

$ cat D139927.cpp 
#include <stddef.h>

void* operator new(size_t, void* p) {
    return p;
}

int a();
void d(int p);

struct U {
    int p;

    U()
    : p(a()) {
    }

    ~U() {
        d(p);
    }
};

void f() {
    U lhs;
    new (&lhs) U;
}
$ g++-8 -c D139927.cpp -Wmaybe-uninitialized -O1
D139927.cpp: In function ‘void f()’:
D139927.cpp:18:10: warning: ‘lhs.U::p’ may be used uninitialized in this
function [-Wmaybe-uninitialized]
         d(p);
         ~^~~
$ 

Increasing -O, as suggested in one of the bugs I found, doesn't help. 
godbolt.org's Compiler Explorer suggests it was a regression between 6.4 and
7.1 and abides in 9 and the latest trunk available over there.  Sorry about the
#include but it gave me a portable size_t for the placement new, which I failed
to simplify away.

Reply via email to