[clang] 0e42ec1 - DebugInfo: Correct printing empty template parameter packs
David Blaikie via cfe-commits
cfe-commits at lists.llvm.org
Mon Aug 30 10:21:00 PDT 2021
Author: David Blaikie
Date: 2021-08-30T10:20:12-07:00
New Revision: 0e42ec1add336e7fbf6cc1f82f663cabe48bf55e
URL: https://github.com/llvm/llvm-project/commit/0e42ec1add336e7fbf6cc1f82f663cabe48bf55e
DIFF: https://github.com/llvm/llvm-project/commit/0e42ec1add336e7fbf6cc1f82f663cabe48bf55e.diff
LOG: 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 >>.
Added:
Modified:
clang/lib/AST/TypePrinter.cpp
clang/test/CodeGenCXX/debug-info-template.cpp
Removed:
################################################################################
diff --git a/clang/lib/AST/TypePrinter.cpp b/clang/lib/AST/TypePrinter.cpp
index b66e432b98e9a..aef1e4f3f4953 100644
--- a/clang/lib/AST/TypePrinter.cpp
+++ b/clang/lib/AST/TypePrinter.cpp
@@ -2052,20 +2052,21 @@ printTo(raw_ostream &OS, ArrayRef<TA> 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 0255ec9df00fa..2ce0166590aa1 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<t1<int>>();
// CHECK: !DISubprogram(name: "f1<IndirectDefaultArgument::t1<int, int> >",
+} // namespace IndirectDefaultArgument
+
+namespace EmptyTrailingPack {
+template<typename T>
+struct t1 { };
+template<typename T, typename ...Ts>
+void f1() {
+}
+template void f1<t1<int>>();
+// CHECK: !DISubprogram(name: "f1<EmptyTrailingPack::t1<int> >",
+} // namespace EmptyTrailingPack
+
+namespace EmptyInnerPack {
+template<typename ...Ts, typename T = int>
+void f1() {
}
+template void f1<>();
+// CHECK: !DISubprogram(name: "f1<int>",
+} // namespace EmptyInnerPack
More information about the cfe-commits
mailing list