@@ -3376,7 +3376,11 @@ namespace {
3376
3376
3377
3377
// / Emit diagnostics for incorrect usage of SWIFT_RETURNS_RETAINED and
3378
3378
// / SWIFT_RETURNS_UNRETAINED
3379
- void checkBridgingAttrs (const clang::FunctionDecl *decl) {
3379
+ void checkBridgingAttrs (const clang::NamedDecl *decl) {
3380
+ assert (isa<clang::FunctionDecl>(decl) ||
3381
+ isa<clang::ObjCMethodDecl>(decl) &&
3382
+ " checkBridgingAttrs called with a clang::NamedDecl which is "
3383
+ " neither clang::FunctionDecl nor clang::ObjCMethodDecl" );
3380
3384
bool returnsRetainedAttrIsPresent = false ;
3381
3385
bool returnsUnretainedAttrIsPresent = false ;
3382
3386
if (decl->hasAttrs ()) {
@@ -3392,14 +3396,19 @@ namespace {
3392
3396
}
3393
3397
3394
3398
HeaderLoc loc (decl->getLocation ());
3395
- if (isForeignReferenceTypeWithoutImmortalAttrs (decl->getReturnType ())) {
3399
+ const auto retType =
3400
+ isa<clang::FunctionDecl>(decl)
3401
+ ? dyn_cast<clang::FunctionDecl>(decl)->getReturnType ()
3402
+ : dyn_cast<clang::ObjCMethodDecl>(decl)->getReturnType ();
3403
+ if (isForeignReferenceTypeWithoutImmortalAttrs (retType)) {
3396
3404
if (returnsRetainedAttrIsPresent && returnsUnretainedAttrIsPresent) {
3397
3405
Impl.diagnose (loc, diag::both_returns_retained_returns_unretained,
3398
3406
decl);
3399
3407
} else if (!returnsRetainedAttrIsPresent &&
3400
3408
!returnsUnretainedAttrIsPresent) {
3401
- bool unannotatedCxxAPIWarningNeeded = false ;
3402
- if (!isa<clang::CXXDeductionGuideDecl>(decl)) {
3409
+ bool unannotatedAPIWarningNeeded = false ;
3410
+ if (isa<clang::FunctionDecl>(decl) &&
3411
+ !isa<clang::CXXDeductionGuideDecl>(decl)) {
3403
3412
if (const auto *methodDecl = dyn_cast<clang::CXXMethodDecl>(decl)) {
3404
3413
// FIXME: In the future we should support SWIFT_RETURNS_RETAINED
3405
3414
// and SWIFT_RETURNS_UNRETAINED for overloaded C++ operators
@@ -3409,15 +3418,17 @@ namespace {
3409
3418
!methodDecl->isOverloadedOperator () &&
3410
3419
methodDecl->isUserProvided ()) {
3411
3420
// normal c++ member method
3412
- unannotatedCxxAPIWarningNeeded = true ;
3421
+ unannotatedAPIWarningNeeded = true ;
3413
3422
}
3414
3423
} else {
3415
- // global or top-level function
3416
- unannotatedCxxAPIWarningNeeded = true ;
3424
+ // global or top-level C/C++ function
3425
+ unannotatedAPIWarningNeeded = true ;
3417
3426
}
3427
+ } else if (isa<clang::ObjCMethodDecl>(decl)) {
3428
+ unannotatedAPIWarningNeeded = true ;
3418
3429
}
3419
3430
3420
- if (unannotatedCxxAPIWarningNeeded ) {
3431
+ if (unannotatedAPIWarningNeeded ) {
3421
3432
HeaderLoc loc (decl->getLocation ());
3422
3433
Impl.diagnose (loc, diag::no_returns_retained_returns_unretained,
3423
3434
decl);
@@ -4560,6 +4571,8 @@ namespace {
4560
4571
if (!dc)
4561
4572
return nullptr ;
4562
4573
4574
+ checkBridgingAttrs (decl);
4575
+
4563
4576
// While importing the DeclContext, we might have imported the decl
4564
4577
// itself.
4565
4578
auto Known = Impl.importDeclCached (decl, getVersion ());
0 commit comments