diff --git a/clang/include/clang/AST/Decl.h b/clang/include/clang/AST/Decl.h index 97081ee6b9a2..db13e2597907 100644 --- a/clang/include/clang/AST/Decl.h +++ b/clang/include/clang/AST/Decl.h @@ -1780,6 +1780,17 @@ public: return isDefined(Definition); } + /// \brief Get the definition for this declaration. + FunctionDecl *getDefinition() { + const FunctionDecl *Definition; + if (isDefined(Definition)) + return const_cast(Definition); + return nullptr; + } + const FunctionDecl *getDefinition() const { + return const_cast(this)->getDefinition(); + } + /// getBody - Retrieve the body (definition) of the function. The /// function body might be in any of the (re-)declarations of this /// function. The variant that accepts a FunctionDecl pointer will diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp index 6f7a13d63223..c0ccbbf62410 100644 --- a/clang/lib/Sema/SemaDecl.cpp +++ b/clang/lib/Sema/SemaDecl.cpp @@ -2327,11 +2327,8 @@ static const Decl *getDefinition(const Decl *D) { return Def; return VD->getActingDefinition(); } - if (const FunctionDecl *FD = dyn_cast(D)) { - const FunctionDecl* Def; - if (FD->isDefined(Def)) - return Def; - } + if (const FunctionDecl *FD = dyn_cast(D)) + return FD->getDefinition(); return nullptr; } diff --git a/clang/lib/Sema/SemaLookup.cpp b/clang/lib/Sema/SemaLookup.cpp index 9160a3f67413..e2550824fb69 100644 --- a/clang/lib/Sema/SemaLookup.cpp +++ b/clang/lib/Sema/SemaLookup.cpp @@ -4936,8 +4936,8 @@ void Sema::diagnoseTypo(const TypoCorrection &Correction, static NamedDecl *getDefinitionToImport(NamedDecl *D) { if (VarDecl *VD = dyn_cast(D)) return VD->getDefinition(); - if (const FunctionDecl *FD = dyn_cast(D)) - return FD->isDefined(FD) ? const_cast(FD) : nullptr; + if (FunctionDecl *FD = dyn_cast(D)) + return FD->getDefinition(); if (TagDecl *TD = dyn_cast(D)) return TD->getDefinition(); if (ObjCInterfaceDecl *ID = dyn_cast(D))