Skip to content

Commit 484f847

Browse files
authored
Merge pull request swiftlang#63636 from plotfi/plotfi-call-to-generated-init-with-nsstring
[C++-Interop] Allow for calling automatically synthesized ctors of arc types
2 parents 40f05fa + 4f2f348 commit 484f847

File tree

4 files changed

+50
-1
lines changed

4 files changed

+50
-1
lines changed

lib/ClangImporter/ImportType.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1271,8 +1271,8 @@ static bool canBridgeTypes(ImportTypeKind importKind) {
12711271
case ImportTypeKind::Variable:
12721272
case ImportTypeKind::AuditedVariable:
12731273
case ImportTypeKind::Enum:
1274-
return false;
12751274
case ImportTypeKind::RecordField:
1275+
return false;
12761276
case ImportTypeKind::Result:
12771277
case ImportTypeKind::AuditedResult:
12781278
case ImportTypeKind::Parameter:
@@ -1604,6 +1604,10 @@ static ImportedType adjustTypeForConcreteImport(
16041604
// structs, at which point we should really be checking the lifetime
16051605
// qualifiers.
16061606
case clang::Qualifiers::OCL_Strong:
1607+
if (!impl.SwiftContext.LangOpts.EnableCXXInterop) {
1608+
return {Type(), false};
1609+
}
1610+
break;
16071611
case clang::Qualifiers::OCL_Weak:
16081612
return {Type(), false};
16091613
case clang::Qualifiers::OCL_Autoreleasing:
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#import <Foundation/Foundation.h>
2+
3+
struct S {
4+
NSString *_Nullable A;
5+
NSString *_Nullable B;
6+
NSString *_Nullable C;
7+
8+
void dump() const {
9+
printf("%s\n", [A UTF8String]);
10+
printf("%s\n", [B UTF8String]);
11+
printf("%s\n", [C UTF8String]);
12+
}
13+
};
14+

test/Interop/Cxx/objc-correctness/Inputs/module.modulemap

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,9 @@ module ProtocolNamingConflict [extern_c] {
33
requires objc
44
}
55

6+
module CxxClassWithNSStringInit [extern_c] {
7+
header "cxx-class-with-arc-fields-ctor.h"
8+
requires objc
9+
requires cplusplus
10+
}
11+
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// RUN: %target-swift-ide-test -print-module -module-to-print=CxxClassWithNSStringInit -I %S/Inputs -source-filename=x -enable-experimental-cxx-interop -enable-objc-interop | %FileCheck -check-prefix=CHECK-IDE-TEST %s
2+
// RUN: %target-swift-frontend -I %S/Inputs -enable-experimental-cxx-interop -emit-ir %s | %FileCheck %s
3+
4+
5+
// REQUIRES: objc_interop
6+
7+
import Foundation
8+
import CxxClassWithNSStringInit
9+
10+
// CHECK-IDE-TEST: struct S {
11+
// CHECK-IDE-TEST: init()
12+
// CHECK-IDE-TEST: init(A: NSString?, B: NSString?, C: NSString?)
13+
// CHECK-IDE-TEST: var A: NSString?
14+
// CHECK-IDE-TEST: var B: NSString?
15+
// CHECK-IDE-TEST: var C: NSString?
16+
// CHECK-IDE-TEST: }
17+
18+
var foo: NSString? = "foo"
19+
var bar: NSString? = "bar"
20+
var baz: NSString? = "baz"
21+
var s = S(A: foo, B: bar, C: baz)
22+
s.dump()
23+
24+
// CHECK: call {{.*}} @_ZN1SC1ERKS_
25+
// CHECK: call {{.*}} @_ZNK1S4dumpEv

0 commit comments

Comments
 (0)