[clang] Fix printing of templated records. (PR #86339)
Zahira Ammarguellat via cfe-commits
cfe-commits at lists.llvm.org
Fri Mar 22 13:57:21 PDT 2024
https://github.com/zahiraam created https://github.com/llvm/llvm-project/pull/86339
None
>From ab7d280abf053b67b716e0723e2e70876e639810 Mon Sep 17 00:00:00 2001
From: Zahira Ammarguellat <zahira.ammarguellat at intel.com>
Date: Fri, 22 Mar 2024 13:55:44 -0700
Subject: [PATCH] Fix printing of templated records.
---
clang/lib/AST/TypePrinter.cpp | 5 -----
clang/unittests/AST/DeclPrinterTest.cpp | 21 +++++++++++++++++++++
2 files changed, 21 insertions(+), 5 deletions(-)
diff --git a/clang/lib/AST/TypePrinter.cpp b/clang/lib/AST/TypePrinter.cpp
index 7032ff2f18468c..d9504f9dcb3899 100644
--- a/clang/lib/AST/TypePrinter.cpp
+++ b/clang/lib/AST/TypePrinter.cpp
@@ -2303,11 +2303,6 @@ printTo(raw_ostream &OS, ArrayRef<TA> Args, const PrintingPolicy &Policy,
} else {
if (!FirstArg)
OS << Comma;
- if (!Policy.SuppressTagKeyword &&
- Argument.getKind() == TemplateArgument::Type &&
- isa<TagType>(Argument.getAsType()))
- OS << Argument.getAsType().getAsString();
- else
// Tries to print the argument with location info if exists.
printArgument(Arg, Policy, ArgOS,
TemplateParameterList::shouldIncludeTypeForArgument(
diff --git a/clang/unittests/AST/DeclPrinterTest.cpp b/clang/unittests/AST/DeclPrinterTest.cpp
index e024c41e03b484..f0e360f9caf44a 100644
--- a/clang/unittests/AST/DeclPrinterTest.cpp
+++ b/clang/unittests/AST/DeclPrinterTest.cpp
@@ -1386,6 +1386,27 @@ TEST(DeclPrinter, TestTemplateArgumentList16) {
ASSERT_TRUE(PrintedDeclCXX11Matches(Code, "NT2", "int NT2 = 5"));
}
+TEST(DeclPrinter, TestCXXRecordDecl17) {
+ ASSERT_TRUE(PrintedDeclCXX98Matches("template<typename T> struct Z {};"
+ "struct X {};"
+ "Z<X> A;",
+ "A",
+ "Z<X> A"));
+ [](PrintingPolicy &Policy) { Policy.SuppressTagKeyword = false; };
+}
+
+TEST(DeclPrinter, TestCXXRecordDecl18) {
+ ASSERT_TRUE(PrintedDeclCXX98Matches("template<typename T> struct Z {};"
+ "struct X {};"
+ "Z<X> A;"
+ "template <typename T1, int>"
+ "struct Y{};"
+ "Y<Z<X>, 2> B;",
+ "B",
+ "Y<Z<X>, 2> B"));
+ [](PrintingPolicy &Policy) { Policy.SuppressTagKeyword = false; };
+}
+
TEST(DeclPrinter, TestFunctionParamUglified) {
llvm::StringLiteral Code = R"cpp(
class __c;
More information about the cfe-commits
mailing list