@@ -8226,18 +8226,27 @@ bool swift::importer::isMutabilityAttr(const clang::SwiftAttrAttr *swiftAttr) {
82268226 swiftAttr->getAttribute () == " nonmutating" ;
82278227}
82288228
8229- static bool importAsUnsafe (ASTContext &context, const clang::RecordDecl *decl,
8229+ static bool importAsUnsafe (ASTContext &context, const clang::NamedDecl *decl,
82308230 const Decl *MappedDecl) {
82318231 if (!context.LangOpts .hasFeature (Feature::SafeInterop) ||
8232- !context.LangOpts .hasFeature (Feature::AllowUnsafeAttribute) || !decl )
8232+ !context.LangOpts .hasFeature (Feature::AllowUnsafeAttribute))
82338233 return false ;
82348234
8235+ if (isa<clang::CXXMethodDecl>(decl) &&
8236+ !evaluateOrDefault (context.evaluator , IsSafeUseOfCxxDecl ({decl, context}),
8237+ {}))
8238+ return true ;
8239+
82358240 if (isa<ClassDecl>(MappedDecl))
82368241 return false ;
82378242
8238- return evaluateOrDefault (
8239- context.evaluator , ClangTypeEscapability ({decl->getTypeForDecl ()}),
8240- CxxEscapability::Unknown) == CxxEscapability::Unknown;
8243+ if (const auto *record = dyn_cast<clang::RecordDecl>(decl))
8244+ return evaluateOrDefault (context.evaluator ,
8245+ ClangTypeEscapability ({record->getTypeForDecl ()}),
8246+ CxxEscapability::Unknown) ==
8247+ CxxEscapability::Unknown;
8248+
8249+ return false ;
82418250}
82428251
82438252void
@@ -8419,9 +8428,7 @@ ClangImporter::Implementation::importSwiftAttrAttributes(Decl *MappedDecl) {
84198428 }
84208429 }
84218430
8422- if (seenUnsafe ||
8423- importAsUnsafe (SwiftContext, dyn_cast<clang::RecordDecl>(ClangDecl),
8424- MappedDecl)) {
8431+ if (seenUnsafe || importAsUnsafe (SwiftContext, ClangDecl, MappedDecl)) {
84258432 auto attr = new (SwiftContext) UnsafeAttr (/* implicit=*/ !seenUnsafe);
84268433 MappedDecl->getAttrs ().add (attr);
84278434 }
0 commit comments