Skip to content

Commit 64bcabc

Browse files
authored
Merge pull request #75440 from swiftlang/susmonteiro/cxx-span-hide-constructor
Mark constructor Span(baseAddress, count) deprecated
2 parents cabaa99 + 0ef5012 commit 64bcabc

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

lib/ClangImporter/ClangDerivedConformances.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1218,6 +1218,10 @@ void swift::conformToCxxSpanIfNeeded(ClangImporter::Implementation &impl,
12181218
impl.importDecl(constructorDecl, impl.CurrentVersion);
12191219
if (!importedConstructor)
12201220
return;
1221+
1222+
auto attr = AvailableAttr::createPlatformAgnostic(importedConstructor->getASTContext(), "use 'init(_:)' instead.", "", PlatformAgnosticAvailabilityKind::Deprecated);
1223+
importedConstructor->getAttrs().add(attr);
1224+
12211225
decl->addMember(importedConstructor);
12221226

12231227
impl.addSynthesizedTypealias(decl, ctx.Id_Element,
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// RUN: %target-typecheck-verify-swift -I %S/Inputs -enable-experimental-cxx-interop -Xcc -std=c++20 2>&1
2+
3+
// FIXME swift-ci linux tests do not support std::span
4+
// UNSUPPORTED: OS=linux-gnu
5+
6+
import StdSpan
7+
8+
let arr: [Int32] = [1, 2, 3]
9+
arr.withUnsafeBufferPointer { ubpointer in
10+
let _ = ConstSpan(ubpointer) // okay
11+
let _ = ConstSpan(ubpointer.baseAddress!, ubpointer.count)
12+
// expected-warning@-1 {{'init(_:_:)' is deprecated: use 'init(_:)' instead.}}
13+
}

0 commit comments

Comments
 (0)