Skip to content

[cxx-interop] Fix infinite recursion of PackExpansion type. #34427

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 2, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 25 additions & 16 deletions lib/ClangImporter/ImportType.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -830,23 +830,32 @@ namespace {
return { mappedType, underlyingResult.Hint };
}

#define SUGAR_TYPE(KIND) \
ImportResult Visit##KIND##Type(const clang::KIND##Type *type) { \
return Visit(type->desugar()); \
}
SUGAR_TYPE(TypeOfExpr)
SUGAR_TYPE(TypeOf)
SUGAR_TYPE(Decltype)
SUGAR_TYPE(UnaryTransform)
SUGAR_TYPE(Elaborated)
SUGAR_TYPE(SubstTemplateTypeParm)
SUGAR_TYPE(TemplateSpecialization)
SUGAR_TYPE(Auto)
SUGAR_TYPE(DeducedTemplateSpecialization)
SUGAR_TYPE(Adjusted)
SUGAR_TYPE(PackExpansion)
SUGAR_TYPE(Attributed)
// TODO: add custom visitors for these types.
#define MAYBE_SUGAR_TYPE(KIND) \
ImportResult Visit##KIND##Type(const clang::KIND##Type *type) { \
if (type->isSugared()) \
return Visit(type->desugar()); \
return Type(); \
}
MAYBE_SUGAR_TYPE(TypeOfExpr)
MAYBE_SUGAR_TYPE(TypeOf)
MAYBE_SUGAR_TYPE(Decltype)
MAYBE_SUGAR_TYPE(UnaryTransform)
MAYBE_SUGAR_TYPE(TemplateSpecialization)
MAYBE_SUGAR_TYPE(Auto)
MAYBE_SUGAR_TYPE(DeducedTemplateSpecialization)
MAYBE_SUGAR_TYPE(PackExpansion)

// These types are ALWAYS sugared.
#define SUGAR_TYPE(KIND) \
ImportResult Visit##KIND##Type(const clang::KIND##Type *type) { \
return Visit(type->desugar()); \
}
SUGAR_TYPE(MacroQualified)
SUGAR_TYPE(Attributed)
SUGAR_TYPE(Adjusted)
SUGAR_TYPE(SubstTemplateTypeParm)
SUGAR_TYPE(Elaborated)

ImportResult VisitDecayedType(const clang::DecayedType *type) {
clang::ASTContext &clangCtx = Impl.getClangASTContext();
Expand Down
19 changes: 19 additions & 0 deletions test/Interop/Cxx/templates/Inputs/function-templates.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,22 @@ template <class R, class T, class U> R returns_template(T a, U b) {

// Same here:
template <class T> void cannot_infer_template() {}

// TODO: We should support these types. Until then, make sure we don't crash when importing.
template<class... Ts>
void testPackExpansion(Ts...) { }

template<class T>
void testTypeOfExpr(T a, typeof(a + 1) b) { }

template<class T>
void testTypeOf(T a, typeof a b) { }

template<class T>
decltype(auto) testAuto(T arg) {
return arg;
}

// TODO: Add tests for Decltype, UnaryTransform, and TemplateSpecialization with a dependent type once those are supported.

// TODO: Add test for DeducedTemplateSpecializationType once we support class templates.