llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT--> @llvm/pr-subscribers-clang Author: Andrey Ali Khan Bolshakov (bolshakov-a) <details> <summary>Changes</summary> Prior to this change, for the code like this: ```cpp template <int, int = 0> class Tpl; template <int = 0, int> class Tpl; ``` pretty-printing produced an uncompilable code: ```cpp template <int, int = 0> class Tpl; template <int = 0, int = 0> class Tpl; ``` --- Full diff: https://github.com/llvm/llvm-project/pull/161953.diff 2 Files Affected: - (modified) clang/lib/AST/DeclPrinter.cpp (+2-2) - (modified) clang/test/AST/ast-print-record-decl.c (+12-1) ``````````diff diff --git a/clang/lib/AST/DeclPrinter.cpp b/clang/lib/AST/DeclPrinter.cpp index 196057f7b45a4..7001adeff5397 100644 --- a/clang/lib/AST/DeclPrinter.cpp +++ b/clang/lib/AST/DeclPrinter.cpp @@ -1894,7 +1894,7 @@ void DeclPrinter::VisitTemplateTypeParmDecl(const TemplateTypeParmDecl *TTP) { Out << TTP->getDeclName(); } - if (TTP->hasDefaultArgument()) { + if (TTP->hasDefaultArgument() && !TTP->defaultArgumentWasInherited()) { Out << " = "; TTP->getDefaultArgument().getArgument().print(Policy, Out, /*IncludeType=*/false); @@ -1909,7 +1909,7 @@ void DeclPrinter::VisitNonTypeTemplateParmDecl( Policy.CleanUglifiedParameters ? II->deuglifiedName() : II->getName(); printDeclType(NTTP->getType(), Name, NTTP->isParameterPack()); - if (NTTP->hasDefaultArgument()) { + if (NTTP->hasDefaultArgument() && !NTTP->defaultArgumentWasInherited()) { Out << " = "; NTTP->getDefaultArgument().getArgument().print(Policy, Out, /*IncludeType=*/false); diff --git a/clang/test/AST/ast-print-record-decl.c b/clang/test/AST/ast-print-record-decl.c index d3717a4feab83..fd815881ebeb0 100644 --- a/clang/test/AST/ast-print-record-decl.c +++ b/clang/test/AST/ast-print-record-decl.c @@ -290,9 +290,9 @@ KW DeclGroupInMemberList { // A tag decl group in the tag decl's own member list is exercised in // defSelfRef above. +#ifdef __cplusplus // Check out-of-line record definition -#ifdef __cplusplus // PRINT-CXX-NEXT: [[KW]] OutOfLineRecord { KW OutOfLineRecord { // PRINT-CXX-NEXT: [[KW]] Inner @@ -304,4 +304,15 @@ KW OutOfLineRecord { KW OutOfLineRecord::Inner { // PRINT-CXX-NEXT: }; }; + +// PRINT-CXX-NEXT: template <typename, typename = int> [[KW]] SmearedTypeDefArgs; +template <typename, typename = int> KW SmearedTypeDefArgs; +// PRINT-CXX-NEXT: template <typename = int, typename> [[KW]] SmearedTypeDefArgs; +template <typename = int, typename> KW SmearedTypeDefArgs; + +// PRINT-CXX-NEXT: template <int, int = 0> [[KW]] SmearedNTTPDefArgs; +template <int, int = 0> KW SmearedNTTPDefArgs; +// PRINT-CXX-NEXT: template <int = 0, int> [[KW]] SmearedNTTPDefArgs; +template <int = 0, int> KW SmearedNTTPDefArgs; + #endif `````````` </details> https://github.com/llvm/llvm-project/pull/161953 _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
