From d958389d52170be1c6dee93031d34b13809b786b Mon Sep 17 00:00:00 2001 From: Anders Carlsson Date: Sun, 31 May 2009 20:26:12 +0000 Subject: [PATCH] Make sure to copy back arguments that can be changed by FindAllocationOverload. This fixes placement new. (Sebastian, please review). git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@72673 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Sema/SemaExprCXX.cpp | 5 +++++ test/CodeGenCXX/new.cpp | 7 +++++++ 2 files changed, 12 insertions(+) diff --git a/lib/Sema/SemaExprCXX.cpp b/lib/Sema/SemaExprCXX.cpp index a44dcf6f8b..65018daff7 100644 --- a/lib/Sema/SemaExprCXX.cpp +++ b/lib/Sema/SemaExprCXX.cpp @@ -508,6 +508,11 @@ bool Sema::FindAllocationFunctions(SourceLocation StartLoc, SourceRange Range, return true; } + // FindAllocationOverload can change the passed in arguments, so we need to + // copy them back. + if (NumPlaceArgs > 0) + std::copy(&AllocArgs[1], AllocArgs.end(), PlaceArgs); + // FIXME: This is leaked on error. But so much is currently in Sema that it's // easier to clean it in one go. AllocArgs[0]->Destroy(Context); diff --git a/test/CodeGenCXX/new.cpp b/test/CodeGenCXX/new.cpp index fddda2b5b5..d07466db67 100644 --- a/test/CodeGenCXX/new.cpp +++ b/test/CodeGenCXX/new.cpp @@ -3,3 +3,10 @@ void t1() { int* a = new int; } + +// Placement. +void* operator new(unsigned long, void*) throw(); + +void t2(int* a) { + int* b = new (a) int; +} -- 2.50.1