Skip to content

Commit a0ac007

Browse files
committed
[BitwiseCopyable] Don't infer on unref storage.
An imported declaration which has storage that can't be represented in Swift must not be inferred to be BitwiseCopyable: that inference involves looking at the (visible) fields.
1 parent b4dfd44 commit a0ac007

File tree

3 files changed

+29
-0
lines changed

3 files changed

+29
-0
lines changed

include/swift/AST/DiagnosticsSema.def

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7650,6 +7650,8 @@ ERROR(non_bitwise_copyable_type_nonescapable,none,
76507650
"nonescapable type cannot conform to 'BitwiseCopyable'", ())
76517651
ERROR(non_bitwise_copyable_type_cxx_nontrivial,none,
76527652
"non-trivial C++ type cannot conform to 'BitwiseCopyable'", ())
7653+
ERROR(non_bitwise_copyable_c_type_nontrivial,none,
7654+
"type with unrepresentable fields cannot derive conformance to 'BitwiseCopyable'", ())
76537655
ERROR(non_bitwise_copyable_type_member,none,
76547656
"%select{stored property %2|associated value %2}1 of "
76557657
"'BitwiseCopyable'-conforming %kind3 has non-bitwise-copyable type %0",

lib/Sema/TypeCheckBitwise.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,13 @@ static bool checkBitwiseCopyableInstanceStorage(NominalTypeDecl *nominal,
269269
return true;
270270
}
271271

272+
if (sd && sd->hasUnreferenceableStorage()) {
273+
if (!isImplicit(check)) {
274+
sd->diagnose(diag::non_bitwise_copyable_c_type_nontrivial);
275+
}
276+
return true;
277+
}
278+
272279
BitwiseCopyableStorageVisitor visitor(nominal, dc, check);
273280

274281
return visitor.visit(nominal, dc) || visitor.invalid;

test/Sema/bitwse_copyable_import.swift

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,18 @@ struct VoidPointers {
4242
void *p10;
4343
};
4444

45+
struct IntsTrailing {
46+
double d;
47+
float f;
48+
int is[];
49+
};
50+
51+
struct IntsTrailing2 {
52+
double d;
53+
float f;
54+
int is[];
55+
};
56+
4557
//--- Downstream.swift
4658

4759
func take<T : _BitwiseCopyable>(_ t: T) {}
@@ -56,3 +68,11 @@ func passVoidPointers(_ t: VoidPointers) {
5668
take(t)
5769
take(t.p10)
5870
}
71+
func passIntsTrailing(_ t: IntsTrailing) {
72+
take(t) // expected-error{{type_does_not_conform_decl_owner}}
73+
// expected-note@-14{{where_requirement_failure_one_subst}}
74+
}
75+
extension IntsTrailing2 : _BitwiseCopyable {} //expected-error{{bitwise_copyable_outside_module}}
76+
func passIntsTrailing2(_ t: IntsTrailing2) {
77+
take(t)
78+
}

0 commit comments

Comments
 (0)