[clang] c33ebad - Print default template argument if manually specified in typedef declaration.
Vassil Vassilev via cfe-commits
cfe-commits at lists.llvm.org
Tue Jun 29 07:57:35 PDT 2021
Author: Pratyush Das
Date: 2021-06-29T14:57:26Z
New Revision: c33ebad73516ffcf7b00821a430aa6a0199941f0
URL: https://github.com/llvm/llvm-project/commit/c33ebad73516ffcf7b00821a430aa6a0199941f0
DIFF: https://github.com/llvm/llvm-project/commit/c33ebad73516ffcf7b00821a430aa6a0199941f0.diff
LOG: Print default template argument if manually specified in typedef declaration.
If a default template type argument is manually specified to be of the default
type, then it is committed when printing the template.
Differential revision: https://reviews.llvm.org/D103040
Added:
Modified:
clang/lib/AST/TypePrinter.cpp
clang/test/SemaTemplate/class-template-id.cpp
clang/test/SemaTemplate/default-arguments-ast-print.cpp
Removed:
################################################################################
diff --git a/clang/lib/AST/TypePrinter.cpp b/clang/lib/AST/TypePrinter.cpp
index 720cab917a22..47e48506dc96 100644
--- a/clang/lib/AST/TypePrinter.cpp
+++ b/clang/lib/AST/TypePrinter.cpp
@@ -1449,8 +1449,7 @@ void TypePrinter::printTemplateId(const TemplateSpecializationType *T,
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);
}
diff --git a/clang/test/SemaTemplate/class-template-id.cpp b/clang/test/SemaTemplate/class-template-id.cpp
index b32a03e478d9..50cb3ef59ea4 100644
--- a/clang/test/SemaTemplate/class-template-id.cpp
+++ b/clang/test/SemaTemplate/class-template-id.cpp
@@ -9,9 +9,9 @@ A<int, FLOAT> *foo(A<int> *ptr, A<int> const *ptr2, A<int, double> *ptr3) {
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> *'}}
}
}
diff --git a/clang/test/SemaTemplate/default-arguments-ast-print.cpp b/clang/test/SemaTemplate/default-arguments-ast-print.cpp
index 9ed17a79de0d..4623f0a8cdf4 100644
--- a/clang/test/SemaTemplate/default-arguments-ast-print.cpp
+++ b/clang/test/SemaTemplate/default-arguments-ast-print.cpp
@@ -10,3 +10,15 @@ int Foo<int_type, double>::method1() {
// 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;
+}
More information about the cfe-commits
mailing list