mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
Diagnose @safe @unsafe when used together
Fixes rdar://147943857.
This commit is contained in:
@@ -8233,7 +8233,7 @@ NOTE(sending_function_result_with_sending_param_note, none,
|
||||
())
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// MARK: Strict Safety Diagnostics
|
||||
// MARK: Strict Memory Safety Diagnostics
|
||||
//------------------------------------------------------------------------------
|
||||
NOTE(note_reference_to_unsafe_decl,none,
|
||||
"%select{reference|call}0 to unsafe %kind1",
|
||||
@@ -8272,6 +8272,9 @@ NOTE(decl_storage_mark_safe,none,
|
||||
"add '@safe' if this type encapsulates the unsafe storage in "
|
||||
"a safe interface", ())
|
||||
|
||||
ERROR(safe_and_unsafe_attr,none,
|
||||
"%kindbase0 cannot be both @safe and @unsafe", (const Decl *))
|
||||
|
||||
GROUPED_WARNING(unsafe_superclass,StrictMemorySafety,none,
|
||||
"%kindbase0 has superclass involving unsafe type %1",
|
||||
(const ValueDecl *, Type))
|
||||
|
||||
@@ -192,7 +192,6 @@ public:
|
||||
IGNORED_ATTR(AllowFeatureSuppression)
|
||||
IGNORED_ATTR(PreInverseGenerics)
|
||||
IGNORED_ATTR(Safe)
|
||||
IGNORED_ATTR(Unsafe)
|
||||
#undef IGNORED_ATTR
|
||||
|
||||
void visitABIAttr(ABIAttr *attr) {
|
||||
@@ -445,6 +444,7 @@ public:
|
||||
void visitLifetimeAttr(LifetimeAttr *attr);
|
||||
void visitAddressableSelfAttr(AddressableSelfAttr *attr);
|
||||
void visitAddressableForDependenciesAttr(AddressableForDependenciesAttr *attr);
|
||||
void visitUnsafeAttr(UnsafeAttr *attr);
|
||||
};
|
||||
|
||||
} // end anonymous namespace
|
||||
@@ -8140,6 +8140,14 @@ AttributeChecker::visitAddressableForDependenciesAttr(
|
||||
}
|
||||
}
|
||||
|
||||
void AttributeChecker::visitUnsafeAttr(UnsafeAttr *attr) {
|
||||
if (auto safeAttr = D->getAttrs().getAttribute<SafeAttr>()) {
|
||||
D->diagnose(diag::safe_and_unsafe_attr, D)
|
||||
.highlight(attr->getRange())
|
||||
.highlight(safeAttr->getRange());
|
||||
}
|
||||
}
|
||||
|
||||
namespace {
|
||||
|
||||
class ClosureAttributeChecker
|
||||
|
||||
@@ -268,3 +268,6 @@ struct UnsafeWrapTest {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@safe @unsafe
|
||||
struct ConfusedStruct { } // expected-error{{struct 'ConfusedStruct' cannot be both @safe and @unsafe}}
|
||||
|
||||
Reference in New Issue
Block a user