Skip to content

Commit

Permalink
Stop ExtractTypeForDeductionGuide from recursing on TypeSourceInfo
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Erich Keane committed Dec 7, 2020
1 parent 4db9b78 commit 1c98f98
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 2 deletions.
3 changes: 1 addition & 2 deletions clang/lib/Sema/SemaTemplate.cpp
Expand Up @@ -2084,8 +2084,7 @@ class ExtractTypeForDeductionGuide
TypeLocBuilder InnerTLB;
QualType Transformed =
TransformType(InnerTLB, OrigDecl->getTypeSourceInfo()->getTypeLoc());
TypeSourceInfo *TSI =
TransformType(InnerTLB.getTypeSourceInfo(Context, Transformed));
TypeSourceInfo *TSI = InnerTLB.getTypeSourceInfo(Context, Transformed);
if (isa<TypeAliasDecl>(OrigDecl))
Decl = TypeAliasDecl::Create(
Context, Context.getTranslationUnitDecl(), OrigDecl->getBeginLoc(),
Expand Down
40 changes: 40 additions & 0 deletions clang/test/AST/deduction-guides.cpp
Expand Up @@ -37,3 +37,43 @@ HasDeductionGuideTypeAlias()->HasDeductionGuideTypeAlias<int>;
// CHECK: CXXDeductionGuideDecl {{.*}} implicit <deduction guide for HasDeductionGuideTypeAlias> 'auto (HasDeductionGuideTypeAlias<T>) -> HasDeductionGuideTypeAlias<T>'
// CHECK: CXXDeductionGuideDecl {{.*}} <deduction guide for HasDeductionGuideTypeAlias> 'auto () -> HasDeductionGuideTypeAlias<int>'
} // namespace PR46111


namespace PR48177 {
template <class A> struct Base {
using type_alias = A;
};
template<class T, int S, class A>
struct Derived : Base<A> {
using type_alias = typename Derived::type_alias;
Derived(Derived &&, typename Derived::type_alias const&);
Derived(T);
};

template<class T, class A>
Derived(T, A) -> Derived<T, 1, A>;

void init() {
Derived d {1,2};
}
} // namespace PR48177

// CHECK: CXXRecordDecl {{.*}} struct Derived
// CHECK: TypeAliasDecl {{.*}} type_alias 'typename Derived<T, S, A>::type_alias'
// CHECK-NEXT: DependentNameType {{.*}} 'typename Derived<T, S, A>::type_alias' dependent

// CHECK: CXXRecordDecl {{.*}} struct Derived
// CHECK: TypeAliasDecl {{.*}} type_alias 'typename Derived<int, 1, int>::type_alias':'int'
// CHECK-NEXT: ElaboratedType {{.*}} 'typename Derived<int, 1, int>::type_alias' sugar
// CHECK-NEXT: TypedefType {{.*}} 'PR48177::Base<int>::type_alias' sugar
// CHECK-NEXT: TypeAlias {{.*}} 'type_alias'
// CHECK-NEXT: SubstTemplateTypeParmType {{.*}} 'int' sugar
// CHECK-NEXT: TemplateTypeParmType {{.*}} 'A'
// CHECK-NEXT: TemplateTypeParm {{.*}} 'A'
// CHECK-NEXT: BuiltinType {{.*}} 'int'

// CHECK: CXXDeductionGuideDecl {{.*}} implicit <deduction guide for Derived> 'auto (Derived<T, S, A> &&, const typename Derived<T, S, A>::type_alias &) -> Derived<T, S, A>'
// CHECK: CXXDeductionGuideDecl {{.*}} implicit <deduction guide for Derived> 'auto (T) -> Derived<T, S, A>'
// CHECK: CXXDeductionGuideDecl {{.*}} implicit <deduction guide for Derived> 'auto (Derived<T, S, A>) -> Derived<T, S, A>'
// CHECK: CXXDeductionGuideDecl {{.*}} <deduction guide for Derived> 'auto (T, A) -> Derived<T, 1, A>'
// CHECK: CXXDeductionGuideDecl {{.*}} <deduction guide for Derived> 'auto (int, int) -> Derived<int, 1, int>'

0 comments on commit 1c98f98

Please sign in to comment.