Skip to content

Commit c33ebad

Browse files
reikdasvgvassilev
authored andcommitted
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
1 parent 58a2304 commit c33ebad

File tree

3 files changed

+15
-4
lines changed

3 files changed

+15
-4
lines changed

clang/lib/AST/TypePrinter.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1449,8 +1449,7 @@ void TypePrinter::printTemplateId(const TemplateSpecializationType *T,
14491449
T->getTemplateName().print(OS, Policy);
14501450
}
14511451

1452-
const TemplateParameterList *TPL = TD ? TD->getTemplateParameters() : nullptr;
1453-
printTemplateArgumentList(OS, T->template_arguments(), Policy, TPL);
1452+
printTemplateArgumentList(OS, T->template_arguments(), Policy);
14541453
spaceBeforePlaceHolder(OS);
14551454
}
14561455

clang/test/SemaTemplate/class-template-id.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@ A<int, FLOAT> *foo(A<int> *ptr, A<int> const *ptr2, A<int, double> *ptr3) {
99
if (ptr)
1010
return ptr; // okay
1111
else if (ptr2)
12-
return ptr2; // expected-error{{cannot initialize return object of type 'A<int> *' with an lvalue of type 'const A<int> *'}}
12+
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> *'}}
1313
else {
14-
return ptr3; // expected-error{{cannot initialize return object of type 'A<int> *' with an lvalue of type 'A<int, double> *'}}
14+
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> *'}}
1515
}
1616
}
1717

clang/test/SemaTemplate/default-arguments-ast-print.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,15 @@ int Foo<int_type, double>::method1() {
1010
// CHECK: int Foo<int_type, double>::method1()
1111
return 10;
1212
}
13+
14+
int test_typedef() {
15+
typedef Foo<int, double> TypedefArg;
16+
// CHECK: typedef Foo<int, double> TypedefArg;
17+
return 10;
18+
}
19+
20+
int test_typedef2() {
21+
typedef Foo<int> TypedefArg;
22+
// CHECK: typedef Foo<int> TypedefArg;
23+
return 10;
24+
}

0 commit comments

Comments
 (0)