mizvekov created this revision.
mizvekov published this revision for review.
mizvekov added a reviewer: rsmith.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

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 <mizve...@gmail.com>


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D109406

Files:
  clang/lib/Sema/TreeTransform.h
  clang/test/CXX/dcl/dcl.spec/dcl.type/dcl.spec.auto/p6.cpp


Index: clang/test/CXX/dcl/dcl.spec/dcl.type/dcl.spec.auto/p6.cpp
===================================================================
--- clang/test/CXX/dcl/dcl.spec/dcl.type/dcl.spec.auto/p6.cpp
+++ clang/test/CXX/dcl/dcl.spec/dcl.type/dcl.spec.auto/p6.cpp
@@ -76,3 +76,25 @@
   template<class> concept d = true;
   d<,> auto e = 0; // expected-error{{expected expression}}
 }
+
+namespace PR48617 {
+  template <typename...> concept C = true;
+  template <typename...> class A {};
+
+  template <typename... Ts> C<Ts...> auto e(A<Ts...>) { return 0; }
+
+  // FIXME: The error here does not make sense.
+  template auto e<>(A<>);
+  // expected-error@-1 {{explicit instantiation of 'e' does not refer to a 
function template}}
+  // expected-note@-5  {{candidate template ignored: failed template argument 
deduction}}
+
+  // FIXME: Should be able to instantiate this with no errors.
+  template C<int> auto e<int>(A<int>);
+  // expected-error@-1 {{explicit instantiation of 'e' does not refer to a 
function template}}
+  // expected-note@-10 {{candidate template ignored: could not match 'C<int, 
Ts...> auto' against 'C<int> auto'}}
+  
+  template C<> auto e<>(A<>);
+
+  template <typename... Ts> A<Ts...> c(Ts...);
+  int f = e(c(1, 2));
+}
Index: clang/lib/Sema/TreeTransform.h
===================================================================
--- clang/lib/Sema/TreeTransform.h
+++ clang/lib/Sema/TreeTransform.h
@@ -6578,7 +6578,7 @@
   NewTL.setFoundDecl(TL.getFoundDecl());
   NewTL.setLAngleLoc(TL.getLAngleLoc());
   NewTL.setRAngleLoc(TL.getRAngleLoc());
-  for (unsigned I = 0; I < TL.getNumArgs(); ++I)
+  for (unsigned I = 0; I < NewTL.getNumArgs(); ++I)
     NewTL.setArgLocInfo(I, NewTemplateArgs.arguments()[I].getLocInfo());
 
   return Result;


Index: clang/test/CXX/dcl/dcl.spec/dcl.type/dcl.spec.auto/p6.cpp
===================================================================
--- clang/test/CXX/dcl/dcl.spec/dcl.type/dcl.spec.auto/p6.cpp
+++ clang/test/CXX/dcl/dcl.spec/dcl.type/dcl.spec.auto/p6.cpp
@@ -76,3 +76,25 @@
   template<class> concept d = true;
   d<,> auto e = 0; // expected-error{{expected expression}}
 }
+
+namespace PR48617 {
+  template <typename...> concept C = true;
+  template <typename...> class A {};
+
+  template <typename... Ts> C<Ts...> auto e(A<Ts...>) { return 0; }
+
+  // FIXME: The error here does not make sense.
+  template auto e<>(A<>);
+  // expected-error@-1 {{explicit instantiation of 'e' does not refer to a function template}}
+  // expected-note@-5  {{candidate template ignored: failed template argument deduction}}
+
+  // FIXME: Should be able to instantiate this with no errors.
+  template C<int> auto e<int>(A<int>);
+  // expected-error@-1 {{explicit instantiation of 'e' does not refer to a function template}}
+  // expected-note@-10 {{candidate template ignored: could not match 'C<int, Ts...> auto' against 'C<int> auto'}}
+  
+  template C<> auto e<>(A<>);
+
+  template <typename... Ts> A<Ts...> c(Ts...);
+  int f = e(c(1, 2));
+}
Index: clang/lib/Sema/TreeTransform.h
===================================================================
--- clang/lib/Sema/TreeTransform.h
+++ clang/lib/Sema/TreeTransform.h
@@ -6578,7 +6578,7 @@
   NewTL.setFoundDecl(TL.getFoundDecl());
   NewTL.setLAngleLoc(TL.getLAngleLoc());
   NewTL.setRAngleLoc(TL.getRAngleLoc());
-  for (unsigned I = 0; I < TL.getNumArgs(); ++I)
+  for (unsigned I = 0; I < NewTL.getNumArgs(); ++I)
     NewTL.setArgLocInfo(I, NewTemplateArgs.arguments()[I].getLocInfo());
 
   return Result;
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
  • [PATCH] D109406: [clang] f... Matheus Izvekov via Phabricator via cfe-commits

Reply via email to