Please find attached a patch (with testcase) fixing the source range
of an implicitly instantiated friend declaration.

OK to commit?

Enea.
Index: include/clang/ASTMatchers/ASTMatchers.h
===================================================================
--- include/clang/ASTMatchers/ASTMatchers.h	(revision 185773)
+++ include/clang/ASTMatchers/ASTMatchers.h	(working copy)
@@ -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"
@@ -539,6 +540,16 @@
   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
Index: unittests/AST/SourceLocationTest.cpp
===================================================================
--- unittests/AST/SourceLocationTest.cpp	(revision 185773)
+++ unittests/AST/SourceLocationTest.cpp	(working copy)
@@ -222,5 +222,18 @@
       unresolvedConstructExpr(), Lang_CXX11));
 }
 
+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
Index: lib/Sema/SemaTemplateInstantiateDecl.cpp
===================================================================
--- lib/Sema/SemaTemplateInstantiateDecl.cpp	(revision 185757)
+++ lib/Sema/SemaTemplateInstantiateDecl.cpp	(working copy)
@@ -1216,6 +1216,7 @@
                            D->getCanonicalDecl()->getStorageClass(),
                            D->isInlineSpecified(), D->hasWrittenPrototype(),
                            D->isConstexpr());
+  Function->setRangeEnd(D->getSourceRange().getEnd());
 
   if (D->isInlined())
     Function->setImplicitlyInline();
_______________________________________________
cfe-commits mailing list
[email protected]
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits

Reply via email to