From: Stephen Kelly Date: Mon, 30 Jul 2018 20:39:14 +0000 (+0000) Subject: Avoid returning an invalid end source loc X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=fbe44001917342dd307ec93946882706aa907813;p=clang Avoid returning an invalid end source loc git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@338301 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/clang/AST/DeclarationName.h b/include/clang/AST/DeclarationName.h index c9adcbbcde..856f3ab572 100644 --- a/include/clang/AST/DeclarationName.h +++ b/include/clang/AST/DeclarationName.h @@ -558,7 +558,7 @@ public: SourceLocation getBeginLoc() const { return NameLoc; } /// getEndLoc - Retrieve the location of the last token. - SourceLocation getEndLoc() const; + SourceLocation getEndLoc() const { return getLocEnd(); } /// getSourceRange - The range of the declaration name. SourceRange getSourceRange() const LLVM_READONLY { @@ -570,9 +570,11 @@ public: } SourceLocation getLocEnd() const LLVM_READONLY { - SourceLocation EndLoc = getEndLoc(); + SourceLocation EndLoc = getEndLocPrivate(); return EndLoc.isValid() ? EndLoc : getLocStart(); } +private: + SourceLocation getEndLocPrivate() const; }; /// Insertion operator for diagnostics. This allows sending DeclarationName's diff --git a/lib/AST/DeclarationName.cpp b/lib/AST/DeclarationName.cpp index 78c4b9707e..9866d92f61 100644 --- a/lib/AST/DeclarationName.cpp +++ b/lib/AST/DeclarationName.cpp @@ -689,7 +689,7 @@ void DeclarationNameInfo::printName(raw_ostream &OS) const { llvm_unreachable("Unexpected declaration name kind"); } -SourceLocation DeclarationNameInfo::getEndLoc() const { +SourceLocation DeclarationNameInfo::getEndLocPrivate() const { switch (Name.getNameKind()) { case DeclarationName::Identifier: case DeclarationName::CXXDeductionGuideName: