Skip to content

Commit 3ca0d56

Browse files
committed
[cxx-interop] Discard duplicating IteratorTy::iterator_category decls
libc++ recently split the `std` module into many top-level modules: llvm/llvm-project@571178a This broke the logic that conforms C++ iterator types to `UnsafeCxxInputIterator`/`UnsafeCxxRandomAccessIterator`. To determine if a C++ type is an iterator type, we look for its inner type called `iterator_category`. After module std was split, Clang instantiates `std::string::const_iterator::iterator_category` twice and doing a Clang lookup within the `const_iterator` type returns two identical `TypedefDecl`s. Clang itself has logic to merge them, but Swift doesn't. rdar://119270491
1 parent e967219 commit 3ca0d56

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

lib/ClangImporter/ClangDerivedConformances.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,11 @@ getIteratorCategoryDecl(const clang::CXXRecordDecl *clangDecl) {
126126
clang::IdentifierInfo *iteratorCategoryDeclName =
127127
&clangDecl->getASTContext().Idents.get("iterator_category");
128128
auto iteratorCategories = clangDecl->lookup(iteratorCategoryDeclName);
129-
if (!iteratorCategories.isSingleResult())
129+
// If this is a templated typedef, Clang might have instantiated several
130+
// equivalent typedef decls. If they aren't equivalent, Clang has already
131+
// complained about this. Let's assume that they are equivalent. (see
132+
// filterNonConflictingPreviousTypedefDecls in clang/Sema/SemaDecl.cpp)
133+
if (iteratorCategories.empty())
130134
return nullptr;
131135
auto iteratorCategory = iteratorCategories.front();
132136

0 commit comments

Comments
 (0)