Fixes couple of friend declaration -ast-print bug
found by running -ast-print on all-std-headers.cpp
which caused it to go into infinite loop. Now
-ast-print prints all declarations found in
all-std-headers.cpp.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@170928 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/AST/DeclPrinter.cpp b/lib/AST/DeclPrinter.cpp
index 4a7344c..b400522 100644
--- a/lib/AST/DeclPrinter.cpp
+++ b/lib/AST/DeclPrinter.cpp
@@ -580,10 +580,8 @@
void DeclPrinter::VisitFriendDecl(FriendDecl *D) {
if (TypeSourceInfo *TSI = D->getFriendType()) {
- if (CXXRecordDecl *FriendD = TSI->getType()->getAsCXXRecordDecl()) {
- Out << "friend ";
- VisitCXXRecordDecl(FriendD);
- }
+ Out << "friend ";
+ Out << " " << TSI->getType().getAsString(Policy);
}
else if (FunctionDecl *FD =
dyn_cast<FunctionDecl>(D->getFriendDecl())) {
@@ -598,7 +596,7 @@
else if (ClassTemplateDecl *CTD =
dyn_cast<ClassTemplateDecl>(D->getFriendDecl())) {
Out << "friend ";
- VisitClassTemplateDecl(CTD);
+ VisitRedeclarableTemplateDecl(CTD);
}
}
diff --git a/test/Index/comment-cplus-decls.cpp b/test/Index/comment-cplus-decls.cpp
index 3d997a5..29af712 100644
--- a/test/Index/comment-cplus-decls.cpp
+++ b/test/Index/comment-cplus-decls.cpp
@@ -77,7 +77,7 @@
template <typename T> friend class TemplateFriendClass;
};
-// CHECK: <Declaration>friend class Test {\n}</Declaration>
+// CHECK: <Declaration>friend class Test</Declaration>
// CHECK: <Declaration>friend void foo()</Declaration>
// CHECK: <Declaration>friend int int_func()</Declaration>
// CHECK: <Declaration>friend bool operator==(const Test &, const Test &)</Declaration>
@@ -144,3 +144,28 @@
}
// CHECK: <Declaration>void f(const T &t = T())</Declaration>
// CHECK: <Declaration>friend void f(const test3::A &)</Declaration>
+
+class MyClass
+{
+/**
+ * \brief plain friend test.
+*/
+ friend class MyClass;
+};
+// CHECK: <Declaration>friend class MyClass</Declaration>
+
+template<class _Tp> class valarray
+{
+private:
+/**
+ * \brief template friend test.
+*/
+ template <class T> friend class valarray;
+};
+// CHECK: <Declaration>template <class T = unsigned int> class valarray {\n}\ntemplate <class T> class valarray</Declaration>
+// CHECK: <Declaration>friend template <class T> class valarray</Declaration>
+
+class gslice
+{
+ valarray<unsigned> __size_;
+};