aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/clang/AST/DeclBase.h7
-rw-r--r--lib/AST/DeclBase.cpp6
2 files changed, 7 insertions, 6 deletions
diff --git a/include/clang/AST/DeclBase.h b/include/clang/AST/DeclBase.h
index ba948078a6..bfc7607b74 100644
--- a/include/clang/AST/DeclBase.h
+++ b/include/clang/AST/DeclBase.h
@@ -294,9 +294,10 @@ protected:
public:
/// getParent - Returns the containing DeclContext if this is a ScopedDecl,
/// else returns NULL.
- DeclContext *getParent();
- const DeclContext *getParent() const {
- return const_cast<DeclContext*>(this)->getParent();
+ const DeclContext *getParent() const;
+ DeclContext *getParent() {
+ return const_cast<DeclContext*>(
+ const_cast<const DeclContext*>(this)->getParent());
}
bool isFunctionOrMethod() const {
diff --git a/lib/AST/DeclBase.cpp b/lib/AST/DeclBase.cpp
index 7e51ef5010..88d9a20855 100644
--- a/lib/AST/DeclBase.cpp
+++ b/lib/AST/DeclBase.cpp
@@ -353,10 +353,10 @@ DeclContext *Decl::castToDeclContext(const Decl *D) {
// DeclContext Implementation
//===----------------------------------------------------------------------===//
-DeclContext *DeclContext::getParent() {
- if (ScopedDecl *SD = dyn_cast<ScopedDecl>(this))
+const DeclContext *DeclContext::getParent() const {
+ if (const ScopedDecl *SD = dyn_cast<ScopedDecl>(this))
return SD->getDeclContext();
- else if (BlockDecl *BD = dyn_cast<BlockDecl>(this))
+ else if (const BlockDecl *BD = dyn_cast<BlockDecl>(this))
return BD->getParentContext();
else
return NULL;