]> granicus.if.org Git - clang/commitdiff
Don't warn on use of default allocator with an over-aligned type when the
authorNick Lewycky <nicholas@mxc.ca>
Sat, 4 Feb 2012 03:30:14 +0000 (03:30 +0000)
committerNick Lewycky <nicholas@mxc.ca>
Sat, 4 Feb 2012 03:30:14 +0000 (03:30 +0000)
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

lib/Sema/SemaExprCXX.cpp
test/SemaCXX/Inputs/warn-new-overaligned-3.h
test/SemaCXX/warn-new-overaligned-3.cpp

index d0e40ba27134df4a3595f0f443a2e5398a6e291b..793b70789a9cc5fcf4760df2147f63f700f1413f 100644 (file)
@@ -1105,7 +1105,7 @@ Sema::BuildCXXNew(SourceLocation StartLoc, bool UseGlobal,
 
   // 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())){
index 024acc299fe940e4fff62daad778e3d0ff81fa71..d2bd4d509548a09f05a7ab85630e0e774c6f33b4 100644 (file)
@@ -10,3 +10,10 @@ void* operator new[](unsigned long) {
   return 0;
 }
 
+void* operator new(unsigned long, void *) {
+  return 0;
+}
+
+void* operator new[](unsigned long, void *) {
+  return 0;
+}
index 783c03ec5688bdd1edf7b1e6951e5111c74d1cf8..c9a57fb65089a163c7650c2879c206262ea486df 100644 (file)
@@ -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 @@ struct Test {
 
 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;
+};
 }