Don't warn on use of default allocator with an over-aligned type when the
allocator is given the pointer to allocate into.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@149760 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Sema/SemaExprCXX.cpp b/lib/Sema/SemaExprCXX.cpp
index d0e40ba..793b707 100644
--- a/lib/Sema/SemaExprCXX.cpp
+++ b/lib/Sema/SemaExprCXX.cpp
@@ -1105,7 +1105,7 @@
// Warn if the type is over-aligned and is being allocated by global operator
// new.
- if (OperatorNew &&
+ if (NumPlaceArgs == 0 && OperatorNew &&
(OperatorNew->isImplicit() ||
getSourceManager().isInSystemHeader(OperatorNew->getLocStart()))) {
if (unsigned Align = Context.getPreferredTypeAlign(AllocType.getTypePtr())){
diff --git a/test/SemaCXX/Inputs/warn-new-overaligned-3.h b/test/SemaCXX/Inputs/warn-new-overaligned-3.h
index 024acc2..d2bd4d5 100644
--- a/test/SemaCXX/Inputs/warn-new-overaligned-3.h
+++ b/test/SemaCXX/Inputs/warn-new-overaligned-3.h
@@ -10,3 +10,10 @@
return 0;
}
+void* operator new(unsigned long, void *) {
+ return 0;
+}
+
+void* operator new[](unsigned long, void *) {
+ return 0;
+}
diff --git a/test/SemaCXX/warn-new-overaligned-3.cpp b/test/SemaCXX/warn-new-overaligned-3.cpp
index 783c03e..c9a57fb 100644
--- a/test/SemaCXX/warn-new-overaligned-3.cpp
+++ b/test/SemaCXX/warn-new-overaligned-3.cpp
@@ -4,6 +4,7 @@
// where the header here simulates <new>.
#include <warn-new-overaligned-3.h>
+namespace test1 {
struct Test {
template <typename T>
struct SeparateCacheLines {
@@ -15,6 +16,18 @@
void helper() {
Test t;
- new Test; // expected-warning {{type 'Test' requires 256 bytes of alignment and the default allocator only guarantees}}
- new Test[10]; // expected-warning {{type 'Test' requires 256 bytes of alignment and the default allocator only guarantees}}
+ new Test; // expected-warning {{type 'test1::Test' requires 256 bytes of alignment and the default allocator only guarantees}}
+ new Test[10]; // expected-warning {{type 'test1::Test' requires 256 bytes of alignment and the default allocator only guarantees}}
+}
+}
+
+namespace test2 {
+struct helper { int i __attribute__((aligned(256))); };
+
+struct Placement {
+ Placement() {
+ new (d) helper();
+ }
+ helper *d;
+};
}