diff options
author | Enea Zaffanella <zaffanella@cs.unipr.it> | 2013-07-19 18:02:36 +0000 |
---|---|---|
committer | Enea Zaffanella <zaffanella@cs.unipr.it> | 2013-07-19 18:02:36 +0000 |
commit | 25723ce6fce0a96e1a126502aab684e2c238f571 (patch) | |
tree | 13c89ea79eb195c0ec99979682999abfabd8db92 | |
parent | 875356ade3e1c91d0f26cdfa08ee69ad41ec8e52 (diff) | |
download | bcm5719-llvm-25723ce6fce0a96e1a126502aab684e2c238f571.tar.gz bcm5719-llvm-25723ce6fce0a96e1a126502aab684e2c238f571.zip |
Fix source range of implicitly instantiated friend declaration.
llvm-svn: 186702
-rw-r--r-- | clang/include/clang/ASTMatchers/ASTMatchers.h | 11 | ||||
-rw-r--r-- | clang/lib/Sema/SemaTemplateInstantiateDecl.cpp | 1 | ||||
-rw-r--r-- | clang/unittests/AST/SourceLocationTest.cpp | 13 |
3 files changed, 25 insertions, 0 deletions
diff --git a/clang/include/clang/ASTMatchers/ASTMatchers.h b/clang/include/clang/ASTMatchers/ASTMatchers.h index 1414c4ef2f9..20851337ee0 100644 --- a/clang/include/clang/ASTMatchers/ASTMatchers.h +++ b/clang/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<Decl, FriendDecl> friendDecl; + /// \brief Matches statements. /// /// Given diff --git a/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp b/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp index 420ccb167fb..d780a3b7134 100644 --- a/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp +++ b/clang/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/clang/unittests/AST/SourceLocationTest.cpp b/clang/unittests/AST/SourceLocationTest.cpp index 49ecfd3c981..d45c6448c79 100644 --- a/clang/unittests/AST/SourceLocationTest.cpp +++ b/clang/unittests/AST/SourceLocationTest.cpp @@ -244,5 +244,18 @@ TEST(UnresolvedUsingValueDecl, SourceRange) { unresolvedUsingValueDecl())); } +TEST(FriendDecl, InstantiationSourceRange) { + RangeVerifier<FriendDecl> Verifier; + Verifier.expectRange(4, 3, 4, 35); + EXPECT_TRUE(Verifier.match( + "template <typename T> class S;\n" + "template<class T> void operator+(S<T> x);\n" + "template<class T> struct S {\n" + " friend void operator+<>(S<T> src);\n" + "};\n" + "void test(S<double> s) { +s; }", + friendDecl(hasParent(recordDecl(isTemplateInstantiation()))))); +} + } // end namespace ast_matchers } // end namespace clang |