Skip to content

Commit ad7ff59

Browse files
committed
[cxx-interop] Do not treat std::pair as an owned type on Linux
In libstdc++ 11, `std::pair` has a base class `std::__pair_base`, which defines a copy constructor. We still continue not treating `std::pair` as an owned type, just like on other platforms.
1 parent e9dd910 commit ad7ff59

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

lib/ClangImporter/ClangImporter.cpp

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7368,12 +7368,6 @@ static bool hasDestroyTypeOperations(const clang::CXXRecordDecl *decl) {
73687368
}
73697369

73707370
static bool hasCustomCopyOrMoveConstructor(const clang::CXXRecordDecl *decl) {
7371-
// std::pair and std::tuple might have copy and move constructors, but that
7372-
// doesn't mean they are safe to use from Swift, e.g. std::pair<UnsafeType, T>
7373-
if (decl->isInStdNamespace() &&
7374-
(decl->getName() == "pair" || decl->getName() == "tuple")) {
7375-
return false;
7376-
}
73777371
return decl->hasUserDeclaredCopyConstructor() ||
73787372
decl->hasUserDeclaredMoveConstructor();
73797373
}
@@ -7489,6 +7483,13 @@ CxxRecordAsSwiftType::evaluate(Evaluator &evaluator,
74897483
}
74907484

74917485
bool anySubobjectsSelfContained(const clang::CXXRecordDecl *decl) {
7486+
// std::pair and std::tuple might have copy and move constructors, or base
7487+
// classes with copy and move constructors, but they are not self-contained
7488+
// types, e.g. `std::pair<UnsafeType, T>`.
7489+
if (decl->isInStdNamespace() &&
7490+
(decl->getName() == "pair" || decl->getName() == "tuple"))
7491+
return false;
7492+
74927493
if (!decl->getDefinition())
74937494
return false;
74947495

0 commit comments

Comments
 (0)