r199617 - PR18544: don't assert that 'operator new' is not declared inside a namespace;

Richard Smith richard-llvm at metafoo.co.uk
Sun Jan 19 15:25:38 PST 2014


Author: rsmith
Date: Sun Jan 19 17:25:37 2014
New Revision: 199617

URL: http://llvm.org/viewvc/llvm-project?rev=199617&view=rev
Log:
PR18544: don't assert that 'operator new' is not declared inside a namespace;
such an assert will fail in invalid code that does so!

Modified:
    cfe/trunk/lib/AST/Decl.cpp
    cfe/trunk/test/SemaCXX/new-delete.cpp

Modified: cfe/trunk/lib/AST/Decl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/Decl.cpp?rev=199617&r1=199616&r2=199617&view=diff
==============================================================================
--- cfe/trunk/lib/AST/Decl.cpp (original)
+++ cfe/trunk/lib/AST/Decl.cpp Sun Jan 19 17:25:37 2014
@@ -2304,8 +2304,8 @@ bool FunctionDecl::isReservedGlobalPlace
          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::isReplaceableGlobalAl
 
   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::getCorrespondingUnsizedGlo
     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),

Modified: cfe/trunk/test/SemaCXX/new-delete.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/new-delete.cpp?rev=199617&r1=199616&r2=199617&view=diff
==============================================================================
--- cfe/trunk/test/SemaCXX/new-delete.cpp (original)
+++ cfe/trunk/test/SemaCXX/new-delete.cpp Sun Jan 19 17:25:37 2014
@@ -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}}
+}





More information about the cfe-commits mailing list