From 0e42ec1add336e7fbf6cc1f82f663cabe48bf55e Mon Sep 17 00:00:00 2001 From: David Blaikie Date: Mon, 30 Aug 2021 10:06:00 -0700 Subject: [PATCH] DebugInfo: Correct printing empty template parameter packs Empty packs in the non-final position would result in an extra ", ". Empty packs in the final position would result in missing the space between trailing >>. --- clang/lib/AST/TypePrinter.cpp | 15 ++++++++------- clang/test/CodeGenCXX/debug-info-template.cpp | 18 ++++++++++++++++++ 2 files changed, 26 insertions(+), 7 deletions(-) diff --git a/clang/lib/AST/TypePrinter.cpp b/clang/lib/AST/TypePrinter.cpp index b66e432..aef1e4f 100644 --- a/clang/lib/AST/TypePrinter.cpp +++ b/clang/lib/AST/TypePrinter.cpp @@ -2052,20 +2052,21 @@ printTo(raw_ostream &OS, ArrayRef Args, const PrintingPolicy &Policy, // If the last character of our string is '>', add another space to // keep the two '>''s separate tokens. - NeedSpace = Policy.SplitTemplateClosers && !ArgString.empty() && - ArgString.back() == '>'; - FirstArg = false; + if (!ArgString.empty()) { + NeedSpace = Policy.SplitTemplateClosers && ArgString.back() == '>'; + FirstArg = false; + } // Use same template parameter for all elements of Pack if (!IsPack) ParmIndex++; } - if (NeedSpace) - OS << ' '; - - if (!IsPack) + if (!IsPack) { + if (NeedSpace) + OS << ' '; OS << '>'; + } } void clang::printTemplateArgumentList(raw_ostream &OS, diff --git a/clang/test/CodeGenCXX/debug-info-template.cpp b/clang/test/CodeGenCXX/debug-info-template.cpp index 0255ec9..2ce0166 100644 --- a/clang/test/CodeGenCXX/debug-info-template.cpp +++ b/clang/test/CodeGenCXX/debug-info-template.cpp @@ -196,4 +196,22 @@ void f1() { } template void f1>(); // CHECK: !DISubprogram(name: "f1 >", +} // namespace IndirectDefaultArgument + +namespace EmptyTrailingPack { +template +struct t1 { }; +template +void f1() { +} +template void f1>(); +// CHECK: !DISubprogram(name: "f1 >", +} // namespace EmptyTrailingPack + +namespace EmptyInnerPack { +template +void f1() { } +template void f1<>(); +// CHECK: !DISubprogram(name: "f1", +} // namespace EmptyInnerPack -- 2.7.4