[PATCH] D103040: Print default template argument if manually specified in typedef declaration.

Pratyush Das via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Mon May 24 12:05:43 PDT 2021


reikdas created this revision.
reikdas added a reviewer: rsmith.
reikdas requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

If a default template type argument is manually specified to be of the default type, then it is committed when printing the template.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D103040

Files:
  clang/lib/AST/TypePrinter.cpp
  clang/test/SemaTemplate/class-template-id.cpp
  clang/test/SemaTemplate/default-arguments-ast-print.cpp


Index: clang/test/SemaTemplate/default-arguments-ast-print.cpp
===================================================================
--- clang/test/SemaTemplate/default-arguments-ast-print.cpp
+++ clang/test/SemaTemplate/default-arguments-ast-print.cpp
@@ -10,3 +10,15 @@
   // CHECK: int Foo<int_type, double>::method1()
   return 10;
 }
+
+int test_typedef() {
+  typedef Foo<int, double> TypedefArg;
+  // CHECK: typedef Foo<int, double> TypedefArg;
+  return 10;
+}
+
+int test_typedef2() {
+  typedef Foo<int> TypedefArg;
+  // CHECK: typedef Foo<int> TypedefArg;
+  return 10;
+}
Index: clang/test/SemaTemplate/class-template-id.cpp
===================================================================
--- clang/test/SemaTemplate/class-template-id.cpp
+++ clang/test/SemaTemplate/class-template-id.cpp
@@ -9,9 +9,9 @@
   if (ptr)
     return ptr; // okay
   else if (ptr2)
-    return ptr2; // expected-error{{cannot initialize return object of type 'A<int> *' with an lvalue of type 'const A<int> *'}}
+    return ptr2; // expected-error{{cannot initialize return object of type 'A<int, FLOAT> *' (aka 'A<int, float> *') with an lvalue of type 'const A<int> *'}}
   else {
-    return ptr3; // expected-error{{cannot initialize return object of type 'A<int> *' with an lvalue of type 'A<int, double> *'}}
+    return ptr3; // expected-error{{cannot initialize return object of type 'A<int, FLOAT> *' (aka 'A<int, float> *') with an lvalue of type 'A<int, double> *'}}
   }
 }
 
Index: clang/lib/AST/TypePrinter.cpp
===================================================================
--- clang/lib/AST/TypePrinter.cpp
+++ clang/lib/AST/TypePrinter.cpp
@@ -1447,8 +1447,7 @@
     T->getTemplateName().print(OS, Policy);
   }
 
-  const TemplateParameterList *TPL = TD ? TD->getTemplateParameters() : nullptr;
-  printTemplateArgumentList(OS, T->template_arguments(), Policy, TPL);
+  printTemplateArgumentList(OS, T->template_arguments(), Policy);
   spaceBeforePlaceHolder(OS);
 }
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D103040.347471.patch
Type: text/x-patch
Size: 1986 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20210524/eae674c0/attachment.bin>


More information about the cfe-commits mailing list