From: Craig Topper Date: Sun, 10 May 2015 18:40:12 +0000 (+0000) Subject: De-virtualize some const versions of getCanonicalDecl by redirecting to the non-const... X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=117339a2345064b7c77c82608725b31ea2acb05a;p=clang De-virtualize some const versions of getCanonicalDecl by redirecting to the non-const version. Most of the Decl hierarchy already did it this way this just makes the rest consistent. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@236959 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/clang/AST/Decl.h b/include/clang/AST/Decl.h index f8e17268e6..1f7b03ab23 100644 --- a/include/clang/AST/Decl.h +++ b/include/clang/AST/Decl.h @@ -1889,8 +1889,10 @@ public: void setPreviousDeclaration(FunctionDecl * PrevDecl); - virtual const FunctionDecl *getCanonicalDecl() const; FunctionDecl *getCanonicalDecl() override; + const FunctionDecl *getCanonicalDecl() const { + return const_cast(this)->getCanonicalDecl(); + } unsigned getBuiltinID() const; diff --git a/include/clang/AST/DeclCXX.h b/include/clang/AST/DeclCXX.h index 332238fd54..0dbc9dacf7 100644 --- a/include/clang/AST/DeclCXX.h +++ b/include/clang/AST/DeclCXX.h @@ -651,8 +651,8 @@ public: CXXRecordDecl *getCanonicalDecl() override { return cast(RecordDecl::getCanonicalDecl()); } - virtual const CXXRecordDecl *getCanonicalDecl() const { - return cast(RecordDecl::getCanonicalDecl()); + const CXXRecordDecl *getCanonicalDecl() const { + return const_cast(this)->getCanonicalDecl(); } CXXRecordDecl *getPreviousDecl() { @@ -1781,7 +1781,7 @@ public: CXXMethodDecl *getCanonicalDecl() override { return cast(FunctionDecl::getCanonicalDecl()); } - const CXXMethodDecl *getCanonicalDecl() const override { + const CXXMethodDecl *getCanonicalDecl() const { return const_cast(this)->getCanonicalDecl(); } @@ -2326,12 +2326,12 @@ public: /// \brief Set the constructor that this inheriting constructor is based on. void setInheritedConstructor(const CXXConstructorDecl *BaseCtor); - const CXXConstructorDecl *getCanonicalDecl() const override { - return cast(FunctionDecl::getCanonicalDecl()); - } CXXConstructorDecl *getCanonicalDecl() override { return cast(FunctionDecl::getCanonicalDecl()); } + const CXXConstructorDecl *getCanonicalDecl() const { + return const_cast(this)->getCanonicalDecl(); + } // Implement isa/cast/dyncast/etc. static bool classof(const Decl *D) { return classofKind(D->getKind()); } diff --git a/lib/AST/Decl.cpp b/lib/AST/Decl.cpp index 978b1dfc41..173e22f069 100644 --- a/lib/AST/Decl.cpp +++ b/lib/AST/Decl.cpp @@ -2569,10 +2569,6 @@ FunctionDecl::setPreviousDeclaration(FunctionDecl *PrevDecl) { IsInline = true; } -const FunctionDecl *FunctionDecl::getCanonicalDecl() const { - return getFirstDecl(); -} - FunctionDecl *FunctionDecl::getCanonicalDecl() { return getFirstDecl(); } /// \brief Returns a value indicating whether this function