r186702 - Fix source range of implicitly instantiated friend declaration.

Enea Zaffanella zaffanella at cs.unipr.it
Fri Jul 19 11:02:36 PDT 2013


Author: enea
Date: Fri Jul 19 13:02:36 2013
New Revision: 186702

URL: http://llvm.org/viewvc/llvm-project?rev=186702&view=rev
Log:
Fix source range of implicitly instantiated friend declaration.

Modified:
    cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h
    cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp
    cfe/trunk/unittests/AST/SourceLocationTest.cpp

Modified: cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h?rev=186702&r1=186701&r2=186702&view=diff
==============================================================================
--- cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h (original)
+++ cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h Fri Jul 19 13:02:36 2013
@@ -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::VariadicDynCastAllOfMatc
   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

Modified: cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp?rev=186702&r1=186701&r2=186702&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp (original)
+++ cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp Fri Jul 19 13:02:36 2013
@@ -1216,6 +1216,7 @@ Decl *TemplateDeclInstantiator::VisitFun
                            D->getCanonicalDecl()->getStorageClass(),
                            D->isInlineSpecified(), D->hasWrittenPrototype(),
                            D->isConstexpr());
+  Function->setRangeEnd(D->getSourceRange().getEnd());
 
   if (D->isInlined())
     Function->setImplicitlyInline();

Modified: cfe/trunk/unittests/AST/SourceLocationTest.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/AST/SourceLocationTest.cpp?rev=186702&r1=186701&r2=186702&view=diff
==============================================================================
--- cfe/trunk/unittests/AST/SourceLocationTest.cpp (original)
+++ cfe/trunk/unittests/AST/SourceLocationTest.cpp Fri Jul 19 13:02:36 2013
@@ -244,5 +244,18 @@ TEST(UnresolvedUsingValueDecl, SourceRan
       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





More information about the cfe-commits mailing list