]> granicus.if.org Git - clang/commitdiff
More robust check for the special C++0x operator new workaround.
authorSebastian Redl <sebastian.redl@getdesigned.at>
Tue, 15 Mar 2011 20:41:09 +0000 (20:41 +0000)
committerSebastian Redl <sebastian.redl@getdesigned.at>
Tue, 15 Mar 2011 20:41:09 +0000 (20:41 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@127692 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Sema/SemaExceptionSpec.cpp
test/CXX/except/except.spec/p3.cpp

index 1d21b9760c78a4c10d5f78c62298ed67c578922c..490934c4b04b37a78eaba0667b94b4ed58149197 100644 (file)
@@ -396,14 +396,14 @@ bool Sema::CheckEquivalentExceptionSpec(const PartialDiagnostic &DiagID,
         if (Name && Name->getName() == "bad_alloc") {
           // It's called bad_alloc, but is it in std?
           DeclContext* DC = ExRecord->getDeclContext();
-          while (DC && !isa<NamespaceDecl>(DC))
-            DC = DC->getParent();
-          if (DC) {
-            NamespaceDecl* NS = cast<NamespaceDecl>(DC);
+          DC = DC->getEnclosingNamespaceContext();
+          if (NamespaceDecl* NS = dyn_cast<NamespaceDecl>(DC)) {
             IdentifierInfo* NSName = NS->getIdentifier();
+            DC = DC->getParent();
             if (NSName && NSName->getName() == "std" &&
-                isa<TranslationUnitDecl>(NS->getParent()))
+                DC->getEnclosingNamespaceContext()->isTranslationUnit()) {
               return false;
+            }
           }
         }
       }
index 10e027b719a749daecaf04ef546018de1f518d1f..09b1a4e102f93352d504d3722cec508ece91f8fb 100644 (file)
@@ -97,9 +97,9 @@ extern void (*r21)() noexcept(true); // expected-error {{does not match}}
 // As a very special workaround, we allow operator new to match no spec
 // with a throw(bad_alloc) spec, because C++0x makes an incompatible change
 // here.
-namespace std { class bad_alloc {}; }
+extern "C++" { namespace std { class bad_alloc {}; } }
 void* operator new(unsigned long) throw(std::bad_alloc);
 void* operator new(unsigned long);
-void* operator new[](unsigned long) throw(std::bad_alloc);
 void* operator new[](unsigned long);
+void* operator new[](unsigned long) throw(std::bad_alloc);