[clang] Fix printing of templated records. (PR #86339)

2024-03-27 Thread via cfe-commits

mikaelholmen wrote:

> @zahiraam I still get
> 
> ```
> ../../clang/unittests/AST/DeclPrinterTest.cpp:1394:3: error: expression 
> result unused [-Werror,-Wunused-value]
>   [](PrintingPolicy ) { Policy.SuppressTagKeyword = false; };
>   ^
> ../../clang/unittests/AST/DeclPrinterTest.cpp:1405:3: error: expression 
> result unused [-Werror,-Wunused-value]
>   [](PrintingPolicy ) { Policy.SuppressTagKeyword = false; };
>   ^
> ../../clang/unittests/AST/DeclPrinterTest.cpp:1416:3: error: expression 
> result unused [-Werror,-Wunused-value]
>   [](PrintingPolicy ) { Policy.SuppressTagKeyword = true; };
>   ^~~~
> ../../clang/unittests/AST/DeclPrinterTest.cpp:1435:3: error: expression 
> result unused [-Werror,-Wunused-value]
>   [](PrintingPolicy ) { Policy.SuppressTagKeyword = false; };
>   ^
> ../../clang/unittests/AST/DeclPrinterTest.cpp:1455:3: error: expression 
> result unused [-Werror,-Wunused-value]
>   [](PrintingPolicy ) { Policy.SuppressTagKeyword = true; };
>   ^~~~
> 5 errors generated.
> ```
> 
> This has been broken for quite a while now, can you please fix or revert?

Thank you @alinas for fixing the problem in 577e0ef94fb0 !

https://github.com/llvm/llvm-project/pull/86339
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] Fix printing of templated records. (PR #86339)

2024-03-27 Thread via cfe-commits

mikaelholmen wrote:

@zahiraam I still get
```
../../clang/unittests/AST/DeclPrinterTest.cpp:1394:3: error: expression result 
unused [-Werror,-Wunused-value]
  [](PrintingPolicy ) { Policy.SuppressTagKeyword = false; };
  ^
../../clang/unittests/AST/DeclPrinterTest.cpp:1405:3: error: expression result 
unused [-Werror,-Wunused-value]
  [](PrintingPolicy ) { Policy.SuppressTagKeyword = false; };
  ^
../../clang/unittests/AST/DeclPrinterTest.cpp:1416:3: error: expression result 
unused [-Werror,-Wunused-value]
  [](PrintingPolicy ) { Policy.SuppressTagKeyword = true; };
  ^~~~
../../clang/unittests/AST/DeclPrinterTest.cpp:1435:3: error: expression result 
unused [-Werror,-Wunused-value]
  [](PrintingPolicy ) { Policy.SuppressTagKeyword = false; };
  ^
../../clang/unittests/AST/DeclPrinterTest.cpp:1455:3: error: expression result 
unused [-Werror,-Wunused-value]
  [](PrintingPolicy ) { Policy.SuppressTagKeyword = true; };
  ^~~~
5 errors generated.
```
This has been broken for quite a while now, can you please fix or revert?

https://github.com/llvm/llvm-project/pull/86339
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] Fix printing of templated records. (PR #86339)

2024-03-26 Thread Zahira Ammarguellat via cfe-commits

zahiraam wrote:

oh! I think I know what the issue is. I have a fix for it. PR following up.

https://github.com/llvm/llvm-project/pull/86339
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] Fix printing of templated records. (PR #86339)

2024-03-26 Thread Amy Kwan via cfe-commits

amy-kwan wrote:

This also fails on PPC, as well: 
https://lab.llvm.org/buildbot/#/builders/36/builds/43998/steps/12/logs/stdio

https://github.com/llvm/llvm-project/pull/86339
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] Fix printing of templated records. (PR #86339)

2024-03-26 Thread Kazu Hirata via cfe-commits

kazutakahirata wrote:

Looking at other examples, should the lambda expression be the last argument to 
`ASSERT_TRUE`?

https://github.com/llvm/llvm-project/pull/86339
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] Fix printing of templated records. (PR #86339)

2024-03-26 Thread Kazu Hirata via cfe-commits

kazutakahirata wrote:

> Creating a PR with `[](PrintingPolicy [[maybe_unused]] & Policy) { 
> Policy.SuppressTagKeyword = true; };` on those tests.

I get this error while running `ninja check-clang-unit`.  My build tree is 
configured with `-DCMAKE_CXX_COMPILER=/usr/bin/clang++` and 
`-DLLVM_ENABLE_WERROR=On`.

By the way:

```
[](PrintingPolicy [[maybe_unused]] ) { Policy.SuppressTagKeyword = 
false; };
```

would result in:

```
clang/unittests/AST/DeclPrinterTest.cpp:1394:23: error: 'maybe_unused' 
attribute cannot be applied to types
```

```
[[maybe_unused]] [](PrintingPolicy ) { Policy.SuppressTagKeyword = 
false; };
```

would result in:

```
clang/unittests/AST/DeclPrinterTest.cpp:1394:5: error: 'maybe_unused' attribute 
cannot be applied to a statement
```

I don't know where to put `[[maybe_unused]]`.


https://github.com/llvm/llvm-project/pull/86339
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] Fix printing of templated records. (PR #86339)

2024-03-26 Thread Zahira Ammarguellat via cfe-commits

zahiraam wrote:

Creating a PR with 
`[](PrintingPolicy [[maybe_unused]] & Policy) {
Policy.SuppressTagKeyword = true;
  };`
  on those tests.

https://github.com/llvm/llvm-project/pull/86339
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] Fix printing of templated records. (PR #86339)

2024-03-26 Thread Zahira Ammarguellat via cfe-commits

zahiraam wrote:

> I'm getting errors like:
> 
> ```
> llvm-project/clang/unittests/AST/DeclPrinterTest.cpp:1394:3: error: 
> expression result unused [-Werror,-Wunused-value]
>   [](PrintingPolicy ) { Policy.SuppressTagKeyword = false; };
> ```
> 
> This file being a clang test, I am wondering if this is actually part of the 
> test. Shall we put `[[maybe_unused]]` here?

@kazutakahirata  When do you get this error? 

https://github.com/llvm/llvm-project/pull/86339
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] Fix printing of templated records. (PR #86339)

2024-03-26 Thread Kazu Hirata via cfe-commits

kazutakahirata wrote:

I'm getting errors like:

```
llvm-project/clang/unittests/AST/DeclPrinterTest.cpp:1394:3: error: expression 
result unused [-Werror,-Wunused-value]
  [](PrintingPolicy ) { Policy.SuppressTagKeyword = false; };
```

This file being a clang test, I am wondering if this is actually part of the 
test.  Shall we put `[[maybe_unused]]` here?

https://github.com/llvm/llvm-project/pull/86339
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] Fix printing of templated records. (PR #86339)

2024-03-26 Thread Zahira Ammarguellat via cfe-commits

https://github.com/zahiraam closed 
https://github.com/llvm/llvm-project/pull/86339
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] Fix printing of templated records. (PR #86339)

2024-03-26 Thread Zahira Ammarguellat via cfe-commits

zahiraam wrote:

@AaronBallman Thanks!


https://github.com/llvm/llvm-project/pull/86339
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] Fix printing of templated records. (PR #86339)

2024-03-26 Thread Aaron Ballman via cfe-commits

https://github.com/AaronBallman approved this pull request.

Good catch, LGTM!

https://github.com/llvm/llvm-project/pull/86339
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] Fix printing of templated records. (PR #86339)

2024-03-26 Thread Zahira Ammarguellat via cfe-commits

https://github.com/zahiraam edited 
https://github.com/llvm/llvm-project/pull/86339
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] Fix printing of templated records. (PR #86339)

2024-03-26 Thread Zahira Ammarguellat via cfe-commits

https://github.com/zahiraam edited 
https://github.com/llvm/llvm-project/pull/86339
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] Fix printing of templated records. (PR #86339)

2024-03-26 Thread Zahira Ammarguellat via cfe-commits


@@ -2303,11 +2303,6 @@ printTo(raw_ostream , ArrayRef Args, const 
PrintingPolicy ,
 } else {
   if (!FirstArg)
 OS << Comma;
-  if (!Policy.SuppressTagKeyword &&
-  Argument.getKind() == TemplateArgument::Type &&
-  isa(Argument.getAsType()))
-OS << Argument.getAsType().getAsString();
-  else

zahiraam wrote:

This code was wrongly added in 
https://github.com/intel/llvm/commit/6503b015d4a8 and was not reached by any 
tests. Some of our internal testing did hit this and realized the code was 
wrong. Created reproducers from internal tests to show that the code is wrong.

https://github.com/llvm/llvm-project/pull/86339
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] Fix printing of templated records. (PR #86339)

2024-03-25 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Zahira Ammarguellat (zahiraam)


Changes

Fixed the printing of templated argument list and added test case.

---
Full diff: https://github.com/llvm/llvm-project/pull/86339.diff


2 Files Affected:

- (modified) clang/lib/AST/TypePrinter.cpp (-5) 
- (modified) clang/unittests/AST/DeclPrinterTest.cpp (+69) 


``diff
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 , ArrayRef Args, const 
PrintingPolicy ,
 } 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 e024c41e03b484..07fa02bd96e25d 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.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.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.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 ) : innerInstance(inner) {}"
+  "};"
+  "Outer, 5>::NestedStruct nestedInstance(100);",
+  "nestedInstance",
+  "Outer, 5>::NestedStruct nestedInstance(100)"));
+  [](PrintingPolicy ) { 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 ) : innerInstance(inner) {}"
+  "};"
+  "Outer, 5>::NestedStruct nestedInstance(100);",
+  "nestedInstance",
+  "Outer, 5>::NestedStruct nestedInstance(100)"));
+  [](PrintingPolicy ) { Policy.SuppressTagKeyword = true; };
+}
+
 TEST(DeclPrinter, TestFunctionParamUglified) {
   llvm::StringLiteral Code = R"cpp(
 class __c;

``




https://github.com/llvm/llvm-project/pull/86339
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] Fix printing of templated records. (PR #86339)

2024-03-25 Thread Zahira Ammarguellat via cfe-commits

https://github.com/zahiraam ready_for_review 
https://github.com/llvm/llvm-project/pull/86339
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] Fix printing of templated records. (PR #86339)

2024-03-25 Thread Zahira Ammarguellat via cfe-commits

https://github.com/zahiraam edited 
https://github.com/llvm/llvm-project/pull/86339
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] Fix printing of templated records. (PR #86339)

2024-03-25 Thread Zahira Ammarguellat via cfe-commits

https://github.com/zahiraam updated 
https://github.com/llvm/llvm-project/pull/86339

>From ab7d280abf053b67b716e0723e2e70876e639810 Mon Sep 17 00:00:00 2001
From: Zahira Ammarguellat 
Date: Fri, 22 Mar 2024 13:55:44 -0700
Subject: [PATCH 1/2] 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 , ArrayRef Args, const 
PrintingPolicy ,
 } 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 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 struct Z {};"
+  "struct X {};"
+  "Z A;",
+  "A",
+  "Z A"));
+  [](PrintingPolicy ) { 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.SuppressTagKeyword = false; };
+}
+
 TEST(DeclPrinter, TestFunctionParamUglified) {
   llvm::StringLiteral Code = R"cpp(
 class __c;

>From b1623cab26804c368adfea2eec17663e5a04f8d8 Mon Sep 17 00:00:00 2001
From: Zahira Ammarguellat 
Date: Mon, 25 Mar 2024 05:04:47 -0700
Subject: [PATCH 2/2] Fixed format and added tests.

---
 clang/unittests/AST/DeclPrinterTest.cpp | 58 ++---
 1 file changed, 53 insertions(+), 5 deletions(-)

diff --git a/clang/unittests/AST/DeclPrinterTest.cpp 
b/clang/unittests/AST/DeclPrinterTest.cpp
index f0e360f9caf44a..07fa02bd96e25d 100644
--- a/clang/unittests/AST/DeclPrinterTest.cpp
+++ b/clang/unittests/AST/DeclPrinterTest.cpp
@@ -1390,23 +1390,71 @@ TEST(DeclPrinter, TestCXXRecordDecl17) {
   ASSERT_TRUE(PrintedDeclCXX98Matches("template struct Z {};"
   "struct X {};"
   "Z A;",
-  "A",
-  "Z A"));
+  "A", "Z A"));
   [](PrintingPolicy ) { Policy.SuppressTagKeyword = false; };
 }
 
 TEST(DeclPrinter, TestCXXRecordDecl18) {
   ASSERT_TRUE(PrintedDeclCXX98Matches("template struct Z {};"
   "struct X {};"
-  "Z A;" 
+  "Z A;"
   "template "
   "struct Y{};"
   "Y, 2> B;",
-  "B", 
-  "Y, 2> B"));
+  "B", "Y, 2> B"));
   [](PrintingPolicy ) { 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.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) {}"
+  "};"
+   

[clang] Fix printing of templated records. (PR #86339)

2024-03-22 Thread via cfe-commits

github-actions[bot] wrote:



:white_check_mark: With the latest revision this PR passed the Python code 
formatter.

https://github.com/llvm/llvm-project/pull/86339
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] Fix printing of templated records. (PR #86339)

2024-03-22 Thread via cfe-commits

github-actions[bot] wrote:




:warning: C/C++ code formatter, clang-format found issues in your code. 
:warning:



You can test this locally with the following command:


``bash
git-clang-format --diff 3b3de48fd84b8269d5f45ee0a9dc6b7448368424 
ab7d280abf053b67b716e0723e2e70876e639810 -- clang/lib/AST/TypePrinter.cpp 
clang/unittests/AST/DeclPrinterTest.cpp
``





View the diff from clang-format here.


``diff
diff --git a/clang/unittests/AST/DeclPrinterTest.cpp 
b/clang/unittests/AST/DeclPrinterTest.cpp
index f0e360f9ca..a7d8212249 100644
--- a/clang/unittests/AST/DeclPrinterTest.cpp
+++ b/clang/unittests/AST/DeclPrinterTest.cpp
@@ -1390,20 +1390,18 @@ TEST(DeclPrinter, TestCXXRecordDecl17) {
   ASSERT_TRUE(PrintedDeclCXX98Matches("template struct Z {};"
   "struct X {};"
   "Z A;",
-  "A",
-  "Z A"));
+  "A", "Z A"));
   [](PrintingPolicy ) { Policy.SuppressTagKeyword = false; };
 }
 
 TEST(DeclPrinter, TestCXXRecordDecl18) {
   ASSERT_TRUE(PrintedDeclCXX98Matches("template struct Z {};"
   "struct X {};"
-  "Z A;" 
+  "Z A;"
   "template "
   "struct Y{};"
   "Y, 2> B;",
-  "B", 
-  "Y, 2> B"));
+  "B", "Y, 2> B"));
   [](PrintingPolicy ) { Policy.SuppressTagKeyword = false; };
 }
 

``




https://github.com/llvm/llvm-project/pull/86339
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] Fix printing of templated records. (PR #86339)

2024-03-22 Thread Zahira Ammarguellat via cfe-commits

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 
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 , ArrayRef Args, const 
PrintingPolicy ,
 } 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 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 struct Z {};"
+  "struct X {};"
+  "Z A;",
+  "A",
+  "Z A"));
+  [](PrintingPolicy ) { 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.SuppressTagKeyword = false; };
+}
+
 TEST(DeclPrinter, TestFunctionParamUglified) {
   llvm::StringLiteral Code = R"cpp(
 class __c;

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits