From: Enea Zaffanella Date: Fri, 19 Jul 2013 18:02:36 +0000 (+0000) Subject: Fix source range of implicitly instantiated friend declaration. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=de9ed71c696bee936a21323f61548164de0eda13;p=clang Fix source range of implicitly instantiated friend declaration. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@186702 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/clang/ASTMatchers/ASTMatchers.h b/include/clang/ASTMatchers/ASTMatchers.h index 1414c4ef2f..20851337ee 100644 --- a/include/clang/ASTMatchers/ASTMatchers.h +++ b/include/clang/ASTMatchers/ASTMatchers.h @@ -45,6 +45,7 @@ #ifndef LLVM_CLANG_AST_MATCHERS_AST_MATCHERS_H #define LLVM_CLANG_AST_MATCHERS_AST_MATCHERS_H +#include "clang/AST/DeclFriend.h" #include "clang/AST/DeclTemplate.h" #include "clang/ASTMatchers/ASTMatchersInternal.h" #include "clang/ASTMatchers/ASTMatchersMacros.h" @@ -550,6 +551,16 @@ const internal::VariadicDynCastAllOfMatcher< Decl, FunctionTemplateDecl> functionTemplateDecl; +/// \brief Matches friend declarations. +/// +/// Given +/// \code +/// class X { friend void foo(); }; +/// \endcode +/// friendDecl() +/// matches 'friend void foo()'. +const internal::VariadicDynCastAllOfMatcher friendDecl; + /// \brief Matches statements. /// /// Given diff --git a/lib/Sema/SemaTemplateInstantiateDecl.cpp b/lib/Sema/SemaTemplateInstantiateDecl.cpp index 420ccb167f..d780a3b713 100644 --- a/lib/Sema/SemaTemplateInstantiateDecl.cpp +++ b/lib/Sema/SemaTemplateInstantiateDecl.cpp @@ -1216,6 +1216,7 @@ Decl *TemplateDeclInstantiator::VisitFunctionDecl(FunctionDecl *D, D->getCanonicalDecl()->getStorageClass(), D->isInlineSpecified(), D->hasWrittenPrototype(), D->isConstexpr()); + Function->setRangeEnd(D->getSourceRange().getEnd()); if (D->isInlined()) Function->setImplicitlyInline(); diff --git a/unittests/AST/SourceLocationTest.cpp b/unittests/AST/SourceLocationTest.cpp index 49ecfd3c98..d45c6448c7 100644 --- a/unittests/AST/SourceLocationTest.cpp +++ b/unittests/AST/SourceLocationTest.cpp @@ -244,5 +244,18 @@ TEST(UnresolvedUsingValueDecl, SourceRange) { unresolvedUsingValueDecl())); } +TEST(FriendDecl, InstantiationSourceRange) { + RangeVerifier Verifier; + Verifier.expectRange(4, 3, 4, 35); + EXPECT_TRUE(Verifier.match( + "template class S;\n" + "template void operator+(S x);\n" + "template struct S {\n" + " friend void operator+<>(S src);\n" + "};\n" + "void test(S s) { +s; }", + friendDecl(hasParent(recordDecl(isTemplateInstantiation()))))); +} + } // end namespace ast_matchers } // end namespace clang