Skip to content

Commit 4d4ba2d

Browse files
authored
Merge pull request swiftlang#78515 from swiftlang/gaborh/string-safe
[cxx-interop] Consider std::string safe
2 parents c68df8f + 838a754 commit 4d4ba2d

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

lib/ClangImporter/ClangImporter.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5076,6 +5076,7 @@ TinyPtrVector<ValueDecl *> CXXNamespaceMemberLookup::evaluate(
50765076
}
50775077

50785078
static const llvm::StringMap<std::vector<int>> STLConditionalEscapableParams{
5079+
{"basic_string", {0}},
50795080
{"vector", {0}},
50805081
{"array", {0}},
50815082
{"inplace_vector", {0}},

test/Interop/Cxx/class/safe-interop-mode.swift

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,19 +52,20 @@ struct MyContainer {
5252
int end() const { return -1; }
5353
};
5454

55-
using SpanOfInt = Unannotated;
55+
using SpanOfInt = std::span<int>;
5656
using SpanOfIntAlias = SpanOfInt;
5757

5858
//--- test.swift
5959

6060
import Test
6161
import CoreFoundation
62+
import CxxStdlib
6263

6364
// expected-warning@+1{{global function 'useUnsafeParam' involves unsafe code; use '@unsafe' to indicate that its use is not memory-safe}}{{1-1=@unsafe }}
6465
func useUnsafeParam(x: Unannotated) { // expected-note{{reference to unsafe struct 'Unannotated'}}
6566
}
6667

67-
// expected-warning@+2{{global function 'useUnsafeParam2' involves unsafe code; use '@unsafe' to indicate that its use is not memory-safe}}{{10:1-1=@unsafe }}
68+
// expected-warning@+2{{global function 'useUnsafeParam2' involves unsafe code; use '@unsafe' to indicate that its use is not memory-safe}}{{11:1-1=@unsafe }}
6869
@available(SwiftStdlib 5.8, *)
6970
func useUnsafeParam2(x: UnsafeReference) { // expected-note{{reference to unsafe class 'UnsafeReference'}}
7071
}
@@ -81,6 +82,9 @@ func useSafeParams(x: Owner, y: View, z: SafeEscapableAggregate, c: MyContainer)
8182
func useCfType(x: CFArray) {
8283
}
8384

85+
func useString(x: std.string) {
86+
}
87+
8488
// expected-warning@+1{{global function 'useCppSpan' involves unsafe code; use '@unsafe' to indicate that its use is not memory-safe}}
8589
func useCppSpan(x: SpanOfInt) { // expected-note{{reference to unsafe type alias 'SpanOfInt'}}
8690
}

0 commit comments

Comments
 (0)