Skip to content

Commit 279584d

Browse files
committed
[cxx-interop] Prevent Swift from importing fields marked with [[no_unique_address]]
1 parent 7418b25 commit 279584d

File tree

3 files changed

+19
-0
lines changed

3 files changed

+19
-0
lines changed

include/swift/AST/DiagnosticsClangImporter.def

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -373,5 +373,8 @@ NOTE(ptr_to_nonescapable,none,
373373
"pointer to non-escapable type %0 cannot be imported",
374374
(const clang::Type*))
375375

376+
WARNING(unsupported_attribute, none,
377+
"Swift doesn't support fields marked with %0", (StringRef))
378+
376379
#define UNDEFINE_DIAGNOSTIC_MACROS
377380
#include "DefineDiagnosticMacros.h"

lib/ClangImporter/ImportDecl.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4383,6 +4383,15 @@ namespace {
43834383
std::optional<ImportedName> correctSwiftName;
43844384
ImportedName importedName;
43854385

4386+
if (decl->hasAttr<clang::NoUniqueAddressAttr>()) {
4387+
// FIXME: Swift doesn't support fields marked with [[no_unique_address]] rdar://148437848
4388+
4389+
SourceLoc loc = Impl.importSourceLoc(decl->getLocation());
4390+
Impl.diagnose(loc, diag::unsupported_attribute, "[[no_unique_addr]]");
4391+
4392+
return nullptr;
4393+
}
4394+
43864395
std::tie(importedName, correctSwiftName) = importFullName(decl);
43874396
if (!importedName) {
43884397
return nullptr;

test/Interop/Cxx/stdlib/use-std-string.swift

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -490,4 +490,11 @@ StdStringTestSuite.test("pass as a default argument") {
490490
}
491491
#endif
492492

493+
StdStringTestSuite.test("print std::string") {
494+
let cxxString: std.string = "Hello"
495+
print(cxxString)
496+
let swiftString = String(cxxString)
497+
print(swiftString)
498+
}
499+
493500
runAllTests()

0 commit comments

Comments
 (0)