Skip to content

Commit 68b9d8e

Browse files
committed
[clang] fix transformation of template arguments of 'auto' type constraints
See PR48617. When assigning the new template arguments to the new TypeLoc, we were looping on the argument count of the original TypeLoc instead of the new one, which can be different when packs are present. Signed-off-by: Matheus Izvekov <[email protected]> Reviewed By: rsmith Differential Revision: https://reviews.llvm.org/D109406
1 parent 9f5993d commit 68b9d8e

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

clang/lib/Sema/TreeTransform.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6578,7 +6578,7 @@ QualType TreeTransform<Derived>::TransformAutoType(TypeLocBuilder &TLB,
65786578
NewTL.setFoundDecl(TL.getFoundDecl());
65796579
NewTL.setLAngleLoc(TL.getLAngleLoc());
65806580
NewTL.setRAngleLoc(TL.getRAngleLoc());
6581-
for (unsigned I = 0; I < TL.getNumArgs(); ++I)
6581+
for (unsigned I = 0; I < NewTL.getNumArgs(); ++I)
65826582
NewTL.setArgLocInfo(I, NewTemplateArgs.arguments()[I].getLocInfo());
65836583

65846584
return Result;

clang/test/CXX/dcl/dcl.spec/dcl.type/dcl.spec.auto/p6.cpp

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,3 +76,25 @@ namespace PR48593 {
7676
template<class> concept d = true;
7777
d<,> auto e = 0; // expected-error{{expected expression}}
7878
}
79+
80+
namespace PR48617 {
81+
template <typename...> concept C = true;
82+
template <typename...> class A {};
83+
84+
template <typename... Ts> C<Ts...> auto e(A<Ts...>) { return 0; }
85+
86+
// FIXME: The error here does not make sense.
87+
template auto e<>(A<>);
88+
// expected-error@-1 {{explicit instantiation of 'e' does not refer to a function template}}
89+
// expected-note@-5 {{candidate template ignored: failed template argument deduction}}
90+
91+
// FIXME: Should be able to instantiate this with no errors.
92+
template C<int> auto e<int>(A<int>);
93+
// expected-error@-1 {{explicit instantiation of 'e' does not refer to a function template}}
94+
// expected-note@-10 {{candidate template ignored: could not match 'C<int, Ts...> auto' against 'C<int> auto'}}
95+
96+
template C<> auto e<>(A<>);
97+
98+
template <typename... Ts> A<Ts...> c(Ts...);
99+
int f = e(c(1, 2));
100+
}

0 commit comments

Comments
 (0)