summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--clang/include/clang/AST/DeclBase.h4
-rw-r--r--clang/lib/AST/Decl.cpp9
-rw-r--r--clang/lib/AST/DeclBase.cpp20
-rw-r--r--clang/lib/Analysis/Consumed.cpp15
-rw-r--r--clang/lib/Sema/SemaExceptionSpec.cpp11
-rw-r--r--clang/lib/Sema/SemaTemplateInstantiateDecl.cpp6
-rw-r--r--clang/lib/StaticAnalyzer/Checkers/LLVMConventionsChecker.cpp2
-rw-r--r--clang/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp2
-rw-r--r--clang/lib/StaticAnalyzer/Core/ExprEngineCallAndReturn.cpp4
9 files changed, 34 insertions, 39 deletions
diff --git a/clang/include/clang/AST/DeclBase.h b/clang/include/clang/AST/DeclBase.h
index b832123719d..c77b2b60dfc 100644
--- a/clang/include/clang/AST/DeclBase.h
+++ b/clang/include/clang/AST/DeclBase.h
@@ -397,6 +397,8 @@ public:
bool isInAnonymousNamespace() const;
+ bool isInStdNamespace() const;
+
ASTContext &getASTContext() const LLVM_READONLY;
void setAccess(AccessSpecifier AS) {
@@ -1156,6 +1158,8 @@ public:
return DeclKind == Decl::Namespace;
}
+ bool isStdNamespace() const;
+
bool isInlineNamespace() const;
/// \brief Determines whether this context is dependent on a
diff --git a/clang/lib/AST/Decl.cpp b/clang/lib/AST/Decl.cpp
index a783364c677..1c3a5384d35 100644
--- a/clang/lib/AST/Decl.cpp
+++ b/clang/lib/AST/Decl.cpp
@@ -2328,12 +2328,6 @@ bool FunctionDecl::isReservedGlobalPlacementOperator() const {
return (proto->getParamType(1).getCanonicalType() == Context.VoidPtrTy);
}
-static bool isNamespaceStd(const DeclContext *DC) {
- const NamespaceDecl *ND = dyn_cast<NamespaceDecl>(DC->getRedeclContext());
- return ND && isNamed(ND, "std") &&
- ND->getParent()->getRedeclContext()->isTranslationUnit();
-}
-
bool FunctionDecl::isReplaceableGlobalAllocationFunction() const {
if (getDeclName().getNameKind() != DeclarationName::CXXOperatorName)
return false;
@@ -2371,9 +2365,8 @@ bool FunctionDecl::isReplaceableGlobalAllocationFunction() const {
Ty = Ty->getPointeeType();
if (Ty.getCVRQualifiers() != Qualifiers::Const)
return false;
- // FIXME: Recognise nothrow_t in an inline namespace inside std?
const CXXRecordDecl *RD = Ty->getAsCXXRecordDecl();
- return RD && isNamed(RD, "nothrow_t") && isNamespaceStd(RD->getDeclContext());
+ return RD && isNamed(RD, "nothrow_t") && RD->isInStdNamespace();
}
FunctionDecl *
diff --git a/clang/lib/AST/DeclBase.cpp b/clang/lib/AST/DeclBase.cpp
index 1743b91454c..2b1506d191d 100644
--- a/clang/lib/AST/DeclBase.cpp
+++ b/clang/lib/AST/DeclBase.cpp
@@ -251,6 +251,10 @@ bool Decl::isInAnonymousNamespace() const {
return false;
}
+bool Decl::isInStdNamespace() const {
+ return getDeclContext()->isStdNamespace();
+}
+
TranslationUnitDecl *Decl::getTranslationUnitDecl() {
if (TranslationUnitDecl *TUD = dyn_cast<TranslationUnitDecl>(this))
return TUD;
@@ -795,6 +799,22 @@ bool DeclContext::isInlineNamespace() const {
cast<NamespaceDecl>(this)->isInline();
}
+bool DeclContext::isStdNamespace() const {
+ if (!isNamespace())
+ return false;
+
+ const NamespaceDecl *ND = cast<NamespaceDecl>(this);
+ if (ND->isInline()) {
+ return ND->getParent()->isStdNamespace();
+ }
+
+ if (!getParent()->getRedeclContext()->isTranslationUnit())
+ return false;
+
+ const IdentifierInfo *II = ND->getIdentifier();
+ return II && II->isStr("std");
+}
+
bool DeclContext::isDependentContext() const {
if (isFileContext())
return false;
diff --git a/clang/lib/Analysis/Consumed.cpp b/clang/lib/Analysis/Consumed.cpp
index 2027e77bbf2..2b2da2c69a4 100644
--- a/clang/lib/Analysis/Consumed.cpp
+++ b/clang/lib/Analysis/Consumed.cpp
@@ -739,16 +739,6 @@ void ConsumedStmtVisitor::VisitBinaryOperator(const BinaryOperator *BinOp) {
}
}
-static bool isStdNamespace(const DeclContext *DC) {
- if (!DC->isNamespace()) return false;
- while (DC->getParent()->isNamespace())
- DC = DC->getParent();
- const NamespaceDecl *ND = dyn_cast<NamespaceDecl>(DC);
-
- return ND && ND->getName() == "std" &&
- ND->getDeclContext()->isTranslationUnit();
-}
-
void ConsumedStmtVisitor::VisitCallExpr(const CallExpr *Call) {
const FunctionDecl *FunDecl = Call->getDirectCallee();
if (!FunDecl)
@@ -756,9 +746,8 @@ void ConsumedStmtVisitor::VisitCallExpr(const CallExpr *Call) {
// Special case for the std::move function.
// TODO: Make this more specific. (Deferred)
- if (Call->getNumArgs() == 1 &&
- FunDecl->getNameAsString() == "move" &&
- isStdNamespace(FunDecl->getDeclContext())) {
+ if (Call->getNumArgs() == 1 && FunDecl->getNameAsString() == "move" &&
+ FunDecl->isInStdNamespace()) {
copyInfo(Call->getArg(0), Call, CS_Consumed);
return;
}
diff --git a/clang/lib/Sema/SemaExceptionSpec.cpp b/clang/lib/Sema/SemaExceptionSpec.cpp
index 40112a05214..24d82224ddf 100644
--- a/clang/lib/Sema/SemaExceptionSpec.cpp
+++ b/clang/lib/Sema/SemaExceptionSpec.cpp
@@ -468,15 +468,8 @@ bool Sema::CheckEquivalentExceptionSpec(const PartialDiagnostic &DiagID,
IdentifierInfo* Name = ExRecord->getIdentifier();
if (Name && Name->getName() == "bad_alloc") {
// It's called bad_alloc, but is it in std?
- DeclContext* DC = ExRecord->getDeclContext();
- DC = DC->getEnclosingNamespaceContext();
- if (NamespaceDecl* NS = dyn_cast<NamespaceDecl>(DC)) {
- IdentifierInfo* NSName = NS->getIdentifier();
- DC = DC->getParent();
- if (NSName && NSName->getName() == "std" &&
- DC->getEnclosingNamespaceContext()->isTranslationUnit()) {
- return false;
- }
+ if (ExRecord->isInStdNamespace()) {
+ return false;
}
}
}
diff --git a/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp b/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
index 60ec5bbad93..be2db41efd8 100644
--- a/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
+++ b/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
@@ -887,11 +887,7 @@ Decl *TemplateDeclInstantiator::VisitClassTemplateDecl(ClassTemplateDecl *D) {
if (DCParent->isNamespace() &&
cast<NamespaceDecl>(DCParent)->getIdentifier() &&
cast<NamespaceDecl>(DCParent)->getIdentifier()->isStr("tr1")) {
- DeclContext *DCParent2 = DCParent->getParent();
- if (DCParent2->isNamespace() &&
- cast<NamespaceDecl>(DCParent2)->getIdentifier() &&
- cast<NamespaceDecl>(DCParent2)->getIdentifier()->isStr("std") &&
- DCParent2->getParent()->isTranslationUnit())
+ if (cast<Decl>(DCParent)->isInStdNamespace())
Complain = false;
}
}
diff --git a/clang/lib/StaticAnalyzer/Checkers/LLVMConventionsChecker.cpp b/clang/lib/StaticAnalyzer/Checkers/LLVMConventionsChecker.cpp
index 17ebf9edb6b..0b7375a4b61 100644
--- a/clang/lib/StaticAnalyzer/Checkers/LLVMConventionsChecker.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/LLVMConventionsChecker.cpp
@@ -58,7 +58,7 @@ static bool IsStdString(QualType T) {
const TypedefNameDecl *TD = TT->getDecl();
- if (!InNamespace(TD, "std"))
+ if (!TD->isInStdNamespace())
return false;
return TD->getName() == "string";
diff --git a/clang/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp b/clang/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp
index 5679569e1e6..b415d5b53ff 100644
--- a/clang/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp
+++ b/clang/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp
@@ -1514,7 +1514,7 @@ static bool isInStdNamespace(const Decl *D) {
while (const NamespaceDecl *Parent = dyn_cast<NamespaceDecl>(ND->getParent()))
ND = Parent;
- return ND->getName() == "std";
+ return ND->isStdNamespace();
}
diff --git a/clang/lib/StaticAnalyzer/Core/ExprEngineCallAndReturn.cpp b/clang/lib/StaticAnalyzer/Core/ExprEngineCallAndReturn.cpp
index 69831780566..4619f62bd26 100644
--- a/clang/lib/StaticAnalyzer/Core/ExprEngineCallAndReturn.cpp
+++ b/clang/lib/StaticAnalyzer/Core/ExprEngineCallAndReturn.cpp
@@ -387,14 +387,14 @@ static bool IsInStdNamespace(const FunctionDecl *FD) {
const NamespaceDecl *ND = dyn_cast<NamespaceDecl>(DC);
if (!ND)
return false;
-
+
while (const DeclContext *Parent = ND->getParent()) {
if (!isa<NamespaceDecl>(Parent))
break;
ND = cast<NamespaceDecl>(Parent);
}
- return ND->getName() == "std";
+ return ND->isStdNamespace();
}
// The GDM component containing the dynamic dispatch bifurcation info. When
OpenPOWER on IntegriCloud