]> granicus.if.org Git - clang/commitdiff
PR18544: don't assert that 'operator new' is not declared inside a namespace;
authorRichard Smith <richard-llvm@metafoo.co.uk>
Sun, 19 Jan 2014 23:25:37 +0000 (23:25 +0000)
committerRichard Smith <richard-llvm@metafoo.co.uk>
Sun, 19 Jan 2014 23:25:37 +0000 (23:25 +0000)
such an assert will fail in invalid code that does so!

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@199617 91177308-0d34-0410-b5e6-96231b3b80d8

lib/AST/Decl.cpp
test/SemaCXX/new-delete.cpp

index 4e69a9063690ecf66b964c7ee6483a4c3fa88df5..7a1cd71c262870d36929ea307e9f86478da7cc3a 100644 (file)
@@ -2304,8 +2304,8 @@ bool FunctionDecl::isReservedGlobalPlacementOperator() const {
          getDeclName().getCXXOverloadedOperator() == OO_Array_New ||
          getDeclName().getCXXOverloadedOperator() == OO_Array_Delete);
 
-  if (isa<CXXRecordDecl>(getDeclContext())) return false;
-  assert(getDeclContext()->getRedeclContext()->isTranslationUnit());
+  if (!getDeclContext()->getRedeclContext()->isTranslationUnit())
+    return false;
 
   const FunctionProtoType *proto = getType()->castAs<FunctionProtoType>();
   if (proto->getNumArgs() != 2 || proto->isVariadic()) return false;
@@ -2336,7 +2336,10 @@ bool FunctionDecl::isReplaceableGlobalAllocationFunction() const {
 
   if (isa<CXXRecordDecl>(getDeclContext()))
     return false;
-  assert(getDeclContext()->getRedeclContext()->isTranslationUnit());
+
+  // This can only fail for an invalid 'operator new' declaration.
+  if (!getDeclContext()->getRedeclContext()->isTranslationUnit())
+    return false;
 
   const FunctionProtoType *FPT = getType()->castAs<FunctionProtoType>();
   if (FPT->getNumArgs() > 2 || FPT->isVariadic())
@@ -2377,7 +2380,9 @@ FunctionDecl::getCorrespondingUnsizedGlobalDeallocationFunction() const {
     return 0;
   if (isa<CXXRecordDecl>(getDeclContext()))
     return 0;
-  assert(getDeclContext()->getRedeclContext()->isTranslationUnit());
+
+  if (!getDeclContext()->getRedeclContext()->isTranslationUnit())
+    return 0;
 
   if (getNumParams() != 2 || isVariadic() ||
       !Ctx.hasSameType(getType()->castAs<FunctionProtoType>()->getArgType(1),
index 59e2574fa14318724981bbe6b06a0cba4b2be907..175ebe7fcdaa289adde9d84dfe47c6a8cfd3df9e 100644 (file)
@@ -517,3 +517,7 @@ class DeletingPlaceholder {
     return 0;
   }
 };
+
+namespace PR18544 {
+  inline void *operator new(size_t); // expected-error {{'operator new' cannot be declared inside a namespace}}
+}