diff options
-rw-r--r-- | clang/lib/AST/DeclPrinter.cpp | 11 | ||||
-rw-r--r-- | clang/test/Misc/ast-print-out-of-line-func.cpp | 41 |
2 files changed, 52 insertions, 0 deletions
diff --git a/clang/lib/AST/DeclPrinter.cpp b/clang/lib/AST/DeclPrinter.cpp index 5d841a197f2..bc8a34c9365 100644 --- a/clang/lib/AST/DeclPrinter.cpp +++ b/clang/lib/AST/DeclPrinter.cpp @@ -478,6 +478,11 @@ void DeclPrinter::VisitFunctionDecl(FunctionDecl *D) { if (D->isFunctionTemplateSpecialization()) Out << "template<> "; + else if (!D->getDescribedFunctionTemplate()) { + for (unsigned I = 0, NumTemplateParams = D->getNumTemplateParameterLists(); + I < NumTemplateParams; ++I) + printTemplateParameters(D->getTemplateParameterList(I)); + } CXXConstructorDecl *CDecl = dyn_cast<CXXConstructorDecl>(D); CXXConversionDecl *ConversionDecl = dyn_cast<CXXConversionDecl>(D); @@ -1055,6 +1060,12 @@ void DeclPrinter::VisitTemplateDecl(const TemplateDecl *D) { void DeclPrinter::VisitFunctionTemplateDecl(FunctionTemplateDecl *D) { prettyPrintPragmas(D->getTemplatedDecl()); + // Print any leading template parameter lists. + if (const FunctionDecl *FD = D->getTemplatedDecl()) { + for (unsigned I = 0, NumTemplateParams = FD->getNumTemplateParameterLists(); + I < NumTemplateParams; ++I) + printTemplateParameters(FD->getTemplateParameterList(I)); + } VisitRedeclarableTemplateDecl(D); // Never print "instantiations" for deduction guides (they don't really diff --git a/clang/test/Misc/ast-print-out-of-line-func.cpp b/clang/test/Misc/ast-print-out-of-line-func.cpp index 7c4f7ae7f81..7d42f1f4037 100644 --- a/clang/test/Misc/ast-print-out-of-line-func.cpp +++ b/clang/test/Misc/ast-print-out-of-line-func.cpp @@ -52,3 +52,44 @@ void Wrapper::Inner::staticMember() { } // CHECK: void Wrapper::Inner::staticMember() } + +template<int x, typename T> +class TemplateRecord { + void function(); + template<typename U> void functionTemplate(T, U); +}; + +template<int x, typename T> +void TemplateRecord<x, T>::function() { } +// CHECK: template <int x, typename T> void TemplateRecord<x, T>::function() + +template<int x, typename T> +template<typename U> +void TemplateRecord<x, T>::functionTemplate(T, U) { } +// CHECK: template <int x, typename T> template <typename U> void TemplateRecord<x, T>::functionTemplate(T, U) + +template<> +class TemplateRecord<0, int> { + void function(); + template<typename U> void functionTemplate(int, U); +}; + +void TemplateRecord<0, int>::function() { } +// CHECK: void TemplateRecord<0, int>::function() + +template<typename U> +void TemplateRecord<0, int>::functionTemplate(int, U) { } +// CHECK: template <typename U> void TemplateRecord<0, int>::functionTemplate(int, U) + +template<typename T> +struct OuterTemplateRecord { + template<typename U> + struct Inner { + void function(); + }; +}; + +template<typename T> +template<typename U> +void OuterTemplateRecord<T>::Inner<U>::function() { } +// CHECK: template <typename T> template <typename U> void OuterTemplateRecord<T>::Inner<U>::function() |