Skip to content

[cxx-interop] Bail on parameter that are reference types to dependent types. #41810

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
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
8 changes: 8 additions & 0 deletions lib/ClangImporter/ImportType.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2206,6 +2206,14 @@ ParameterList *ClangImporter::Implementation::importFunctionParameterList(
findGenericTypeInGenericDecls(templateParamType, genericParams);
} else {
if (auto refType = dyn_cast<clang::ReferenceType>(paramTy)) {
// We don't support reference type to a dependent type, just bail.
if (refType->getPointeeType()->isDependentType()) {
addImportDiagnostic(
param, Diagnostic(diag::parameter_type_not_imported, param),
param->getSourceRange().getBegin());
return nullptr;
}

paramTy = refType->getPointeeType();
if (!paramTy.isConstQualified())
isInOut = true;
Expand Down
3 changes: 3 additions & 0 deletions test/Interop/Cxx/reference/Inputs/reference.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,7 @@ T &refToTemplate(T &t) { return t; }
template<class T>
const T &constRefToTemplate(const T &t) { return t; }

template<class T>
void refToDependentParam(ClassTemplate<T> &param) { }

#endif // TEST_INTEROP_CXX_REFERENCE_INPUTS_REFERENCE_H
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,5 @@
// CHECK: func constRefToTemplate<T>(_ t: T) -> UnsafePointer<T>

// CHECK-NOT: refToDependent
// CHECK-NOT: refToDependentParam
// CHECK-NOT: dontImportAtomicRef
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,8 @@
// with the fact that the template type paramaters are defaulted.
// TODO: reenable the following checks: (rdar://90587703)
// TODO-CHECK: func defaultedTemplatePointerTypeParam<T>(_ t: UnsafeMutablePointer<T>)
// TODO-CHECK: func defaultedTemplatePointerReferenceTypeParam<T>(_ t: inout OpaquePointer!)
// TODO-CHECK: func defaultedTemplatePointerPointerTypeParam<T>(_ t: UnsafeMutablePointer<OpaquePointer?>!)

// CHECK: func defaultedTemplatePointerTypeParam<T>(_ t: UnsafeMutablePointer<T>)
// We don't support references to dependent types (rdar://89034440).
// CHECK-NOT: defaultedTemplatePointerReferenceTypeParam
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,6 @@
// CHECK: func multipleDependentArgsInferred<T, U>(_ a: Any, _ b: Any, _ c: T, _ d: U) -> Any
// CHECK: func multipleDependentArgs<T, U>(_ a: Any, _ b: Any, T: T.Type, U: U.Type) -> Any
// CHECK: func refToDependent<T>(_ a: inout T) -> Any
// CHECK: func dependentRef<T>(_ a: inout Any, T: T.Type) -> Any
// CHECK: func dependentRefAndRefInferred<T>(_ a: Any, _ b: inout T) -> Any
// We don't support references to dependent types (rdar://89034440).
// CHECK-NOT: dependentRef
// CHECK-NOT: dependentRefAndRefInferred