diff --git a/clang/lib/AST/TypePrinter.cpp b/clang/lib/AST/TypePrinter.cpp index 7032ff2f18468..d9504f9dcb389 100644 --- a/clang/lib/AST/TypePrinter.cpp +++ b/clang/lib/AST/TypePrinter.cpp @@ -2303,11 +2303,6 @@ printTo(raw_ostream &OS, ArrayRef Args, const PrintingPolicy &Policy, } else { if (!FirstArg) OS << Comma; - if (!Policy.SuppressTagKeyword && - Argument.getKind() == TemplateArgument::Type && - isa(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 e024c41e03b48..07fa02bd96e25 100644 --- a/clang/unittests/AST/DeclPrinterTest.cpp +++ b/clang/unittests/AST/DeclPrinterTest.cpp @@ -1386,6 +1386,75 @@ TEST(DeclPrinter, TestTemplateArgumentList16) { ASSERT_TRUE(PrintedDeclCXX11Matches(Code, "NT2", "int NT2 = 5")); } +TEST(DeclPrinter, TestCXXRecordDecl17) { + ASSERT_TRUE(PrintedDeclCXX98Matches("template struct Z {};" + "struct X {};" + "Z A;", + "A", "Z A")); + [](PrintingPolicy &Policy) { Policy.SuppressTagKeyword = false; }; +} + +TEST(DeclPrinter, TestCXXRecordDecl18) { + ASSERT_TRUE(PrintedDeclCXX98Matches("template struct Z {};" + "struct X {};" + "Z A;" + "template " + "struct Y{};" + "Y, 2> B;", + "B", "Y, 2> B")); + [](PrintingPolicy &Policy) { Policy.SuppressTagKeyword = false; }; +} + +TEST(DeclPrinter, TestCXXRecordDecl19) { + ASSERT_TRUE(PrintedDeclCXX98Matches("template struct Z {};" + "struct X {};" + "Z A;" + "template " + "struct Y{};" + "Y, 2> B;", + "B", "Y, 2> B")); + [](PrintingPolicy &Policy) { Policy.SuppressTagKeyword = true; }; +} +TEST(DeclPrinter, TestCXXRecordDecl20) { + ASSERT_TRUE(PrintedDeclCXX98Matches( + "template class Inner;" + "template " + "class Inner{Inner(T val){}};" + "template class Outer {" + "public:" + "struct NestedStruct {" + "int nestedValue;" + "NestedStruct(int val) : nestedValue(val) {}" + "};" + "InnerClass innerInstance;" + "Outer(const InnerClass &inner) : innerInstance(inner) {}" + "};" + "Outer, 5>::NestedStruct nestedInstance(100);", + "nestedInstance", + "Outer, 5>::NestedStruct nestedInstance(100)")); + [](PrintingPolicy &Policy) { Policy.SuppressTagKeyword = false; }; +} + +TEST(DeclPrinter, TestCXXRecordDecl21) { + ASSERT_TRUE(PrintedDeclCXX98Matches( + "template class Inner;" + "template " + "class Inner{Inner(T val){}};" + "template class Outer {" + "public:" + "struct NestedStruct {" + "int nestedValue;" + "NestedStruct(int val) : nestedValue(val) {}" + "};" + "InnerClass innerInstance;" + "Outer(const InnerClass &inner) : innerInstance(inner) {}" + "};" + "Outer, 5>::NestedStruct nestedInstance(100);", + "nestedInstance", + "Outer, 5>::NestedStruct nestedInstance(100)")); + [](PrintingPolicy &Policy) { Policy.SuppressTagKeyword = true; }; +} + TEST(DeclPrinter, TestFunctionParamUglified) { llvm::StringLiteral Code = R"cpp( class __c;