https://gcc.gnu.org/bugzilla/show_bug.cgi?id=61163
Bug ID: 61163 Summary: Placement arguments shared between allocation and deallocation even when copies prohibited Product: gcc Version: 4.8.2 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: hstong at ca dot ibm.com In N3290 subclause 5.3.4 [expr.new] paragraph 21, the leeway to reuse the same copy of the initialized parameter for both the call to the allocation function and the call to the deallocation function is prefaced with "[i]f the implementation is allowed to make a copy". Since, in the case below, list initialization does not involve copying following the call to the converting constructor, there is no copying to speak of and the leeway is not given. GCC performs the reuse anyway. ### SOURCE:> cat gccListInitNewPlacement.cc extern "C" int printf(const char *, ...); struct A { A(const A &) = delete; A(A &&) = delete; A(int) : x(0) { printf("%s\n", __PRETTY_FUNCTION__); } ~A() { printf("%s\n", __PRETTY_FUNCTION__); } int x; }; struct B { static void *operator new(decltype(sizeof(0)) sz, A a) { printf("%d %s\n", a.x++, __PRETTY_FUNCTION__); return ::operator new(sz); } static void operator delete(void *ptr, A a) { printf("%d %s\n", a.x++, __PRETTY_FUNCTION__); return ::operator delete(ptr); } B() { throw 0; } }; int main() { try { new ({0}) B; } catch(...) { } } ### COMPILER INVOCATION:> g++ -std=c++11 -pedantic-errors -Wall -Wextra gccListInitNewPlacement.cc -o gccListInitNewPlacement ### OUTPUT FROM RESULTING BINARY:> ./gccListInitNewPlacement A::A(int) 0 static void* B::operator new(long unsigned int, A) 1 static void B::operator delete(void*, A) A::~A() ### EXPECTED OUTPUT: A::A(int) 0 static void* B::operator new(long unsigned int, A) A::A(int) 0 static void B::operator delete(void*, A) A::~A() A::~A() ### VERSION INFO:> g++ -v Using built-in specs. COLLECT_GCC=g++ COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-pc-cygwin/4.8.2/lto-wrapper.exe Target: x86_64-pc-cygwin Configured with: /cygdrive/i/szsz/tmpp/cygwin64/gcc/gcc-4.8.2-3/src/gcc-4.8.2/configure --srcdir=/cygdrive/i/szsz/tmpp/cygwin64/gcc/gcc-4.8.2-3/src/gcc-4.8.2 --prefix=/usr --exec-prefix=/usr --bindir=/usr/bin --sbindir=/usr/sbin --libexecdir=/usr/libexec --datadir=/usr/share --localstatedir=/var --sysconfdir=/etc --libdir=/usr/lib --datarootdir=/usr/share --docdir=/usr/share/doc/gcc --htmldir=/usr/share/doc/gcc/html -C --build=x86_64-pc-cygwin --host=x86_64-pc-cygwin --target=x86_64-pc-cygwin --without-libiconv-prefix --without-libintl-prefix --enable-shared --enable-shared-libgcc --enable-static --enable-version-specific-runtime-libs --enable-bootstrap --disable-__cxa_atexit --with-dwarf2 --with-tune=generic --enable-languages=ada,c,c++,fortran,lto,objc,obj-c++ --enable-graphite --enable-threads=posix --enable-libatomic --enable-libgomp --disable-libitm --enable-libquadmath --enable-libquadmath-support --enable-libssp --enable-libada --enable-libgcj-sublibs --disable-java-awt --disable-symvers --with-ecj-jar=/usr/share/java/ecj.jar --with-gnu-ld --with-gnu-as --with-cloog-include=/usr/include/cloog-isl --without-libiconv-prefix --without-libintl-prefix --with-system-zlib --libexecdir=/usr/lib Thread model: posix gcc version 4.8.2 (GCC)