Skip to content

Commit 1c98f98

Browse files
author
Erich Keane
committed
Stop ExtractTypeForDeductionGuide from recursing on TypeSourceInfo
As reported in PR48177, the type-deduction extraction ends up going into an infinite loop when the type referred to has a recursive definition. This stops recursing and just substitutes the type-source-info the TypeLocBuilder identified when transforming the base.
1 parent 4db9b78 commit 1c98f98

File tree

2 files changed

+41
-2
lines changed

2 files changed

+41
-2
lines changed

clang/lib/Sema/SemaTemplate.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2084,8 +2084,7 @@ class ExtractTypeForDeductionGuide
20842084
TypeLocBuilder InnerTLB;
20852085
QualType Transformed =
20862086
TransformType(InnerTLB, OrigDecl->getTypeSourceInfo()->getTypeLoc());
2087-
TypeSourceInfo *TSI =
2088-
TransformType(InnerTLB.getTypeSourceInfo(Context, Transformed));
2087+
TypeSourceInfo *TSI = InnerTLB.getTypeSourceInfo(Context, Transformed);
20892088
if (isa<TypeAliasDecl>(OrigDecl))
20902089
Decl = TypeAliasDecl::Create(
20912090
Context, Context.getTranslationUnitDecl(), OrigDecl->getBeginLoc(),

clang/test/AST/deduction-guides.cpp

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,3 +37,43 @@ HasDeductionGuideTypeAlias()->HasDeductionGuideTypeAlias<int>;
3737
// CHECK: CXXDeductionGuideDecl {{.*}} implicit <deduction guide for HasDeductionGuideTypeAlias> 'auto (HasDeductionGuideTypeAlias<T>) -> HasDeductionGuideTypeAlias<T>'
3838
// CHECK: CXXDeductionGuideDecl {{.*}} <deduction guide for HasDeductionGuideTypeAlias> 'auto () -> HasDeductionGuideTypeAlias<int>'
3939
} // namespace PR46111
40+
41+
42+
namespace PR48177 {
43+
template <class A> struct Base {
44+
using type_alias = A;
45+
};
46+
template<class T, int S, class A>
47+
struct Derived : Base<A> {
48+
using type_alias = typename Derived::type_alias;
49+
Derived(Derived &&, typename Derived::type_alias const&);
50+
Derived(T);
51+
};
52+
53+
template<class T, class A>
54+
Derived(T, A) -> Derived<T, 1, A>;
55+
56+
void init() {
57+
Derived d {1,2};
58+
}
59+
} // namespace PR48177
60+
61+
// CHECK: CXXRecordDecl {{.*}} struct Derived
62+
// CHECK: TypeAliasDecl {{.*}} type_alias 'typename Derived<T, S, A>::type_alias'
63+
// CHECK-NEXT: DependentNameType {{.*}} 'typename Derived<T, S, A>::type_alias' dependent
64+
65+
// CHECK: CXXRecordDecl {{.*}} struct Derived
66+
// CHECK: TypeAliasDecl {{.*}} type_alias 'typename Derived<int, 1, int>::type_alias':'int'
67+
// CHECK-NEXT: ElaboratedType {{.*}} 'typename Derived<int, 1, int>::type_alias' sugar
68+
// CHECK-NEXT: TypedefType {{.*}} 'PR48177::Base<int>::type_alias' sugar
69+
// CHECK-NEXT: TypeAlias {{.*}} 'type_alias'
70+
// CHECK-NEXT: SubstTemplateTypeParmType {{.*}} 'int' sugar
71+
// CHECK-NEXT: TemplateTypeParmType {{.*}} 'A'
72+
// CHECK-NEXT: TemplateTypeParm {{.*}} 'A'
73+
// CHECK-NEXT: BuiltinType {{.*}} 'int'
74+
75+
// CHECK: CXXDeductionGuideDecl {{.*}} implicit <deduction guide for Derived> 'auto (Derived<T, S, A> &&, const typename Derived<T, S, A>::type_alias &) -> Derived<T, S, A>'
76+
// CHECK: CXXDeductionGuideDecl {{.*}} implicit <deduction guide for Derived> 'auto (T) -> Derived<T, S, A>'
77+
// CHECK: CXXDeductionGuideDecl {{.*}} implicit <deduction guide for Derived> 'auto (Derived<T, S, A>) -> Derived<T, S, A>'
78+
// CHECK: CXXDeductionGuideDecl {{.*}} <deduction guide for Derived> 'auto (T, A) -> Derived<T, 1, A>'
79+
// CHECK: CXXDeductionGuideDecl {{.*}} <deduction guide for Derived> 'auto (int, int) -> Derived<int, 1, int>'

0 commit comments

Comments
 (0)