Skip to content

[cxx-interop] Correctly check iterator conformances #61540

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
Oct 14, 2022
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
1 change: 1 addition & 0 deletions lib/ClangImporter/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ add_swift_host_library(swiftClangImporter STATIC
target_link_libraries(swiftClangImporter PRIVATE
swiftAST
swiftParse
swiftSema
clangTooling
LLVMBitstreamReader)

Expand Down
4 changes: 2 additions & 2 deletions lib/ClangImporter/ClangDerivedConformances.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -228,9 +228,9 @@ void swift::conformToCxxSequenceIfNeeded(
return;

// Check if RawIterator conforms to UnsafeCxxInputIterator.
auto rawIteratorConformanceRef = decl->getModuleContext()->lookupConformance(
auto rawIteratorConformanceRef = decl->getModuleContext()->conformsToProtocol(
rawIteratorTy, cxxIteratorProto);
if (!rawIteratorConformanceRef.isConcrete())
if (!rawIteratorConformanceRef || !rawIteratorConformanceRef.isConcrete())
return;
auto rawIteratorConformance = rawIteratorConformanceRef.getConcrete();
auto pointeeDecl =
Expand Down
12 changes: 12 additions & 0 deletions test/Interop/Cxx/stdlib/overlay/Inputs/custom-sequence.h
Original file line number Diff line number Diff line change
Expand Up @@ -86,4 +86,16 @@ struct HasBeginEndReturnRef {
const ConstIterator &end() const { return e; }
};

template <typename A> struct NoDefinition;

template <typename A, typename NoDef = NoDefinition<A>>
struct HasTemplatedIterator {
typedef NoDef* iterator; // OpaquePointer

iterator begin() const;
iterator end() const;
};

typedef HasTemplatedIterator<int> HasUninstantiatableIterator;

#endif // TEST_INTEROP_CXX_STDLIB_INPUTS_CUSTOM_SEQUENCE_H
Original file line number Diff line number Diff line change
Expand Up @@ -58,3 +58,9 @@
// CHECK-NOT: typealias Iterator
// CHECK-NOT: typealias RawIterator
// CHECK: }
// CHECK: struct __CxxTemplateInst20HasTemplatedIteratorIi12NoDefinitionIiEE {
// CHECK-NOT: typealias Element
// CHECK-NOT: typealias Iterator
// CHECK-NOT: typealias RawIterator
// CHECK: }
// CHECK: typealias HasUninstantiatableIterator = __CxxTemplateInst20HasTemplatedIteratorIi12NoDefinitionIiEE