File tree Expand file tree Collapse file tree 2 files changed +24
-1
lines changed Expand file tree Collapse file tree 2 files changed +24
-1
lines changed Original file line number Diff line number Diff line change @@ -4309,7 +4309,8 @@ class CheckEffectsCoverage : public EffectsHandlingWalker<CheckEffectsCoverage>
4309
4309
Ctx.Diags .diagnose (S->getForLoc (), diag::for_unsafe_without_unsafe)
4310
4310
.fixItInsert (insertionLoc, " unsafe " );
4311
4311
}
4312
- } else if (S->getUnsafeLoc ().isValid ()) {
4312
+ } else if (S->getUnsafeLoc ().isValid () &&
4313
+ Ctx.LangOpts .hasFeature (Feature::StrictMemorySafety)) {
4313
4314
// Extraneous "unsafe" on the sequence.
4314
4315
Ctx.Diags .diagnose (S->getUnsafeLoc (), diag::no_unsafe_in_unsafe_for)
4315
4316
.fixItRemove (S->getUnsafeLoc ());
@@ -4343,6 +4344,9 @@ class CheckEffectsCoverage : public EffectsHandlingWalker<CheckEffectsCoverage>
4343
4344
}
4344
4345
4345
4346
void diagnoseRedundantUnsafe (UnsafeExpr *E) const {
4347
+ if (!Ctx.LangOpts .hasFeature (Feature::StrictMemorySafety))
4348
+ return ;
4349
+
4346
4350
if (auto *SVE = SingleValueStmtExpr::tryDigOutSingleValueStmtExpr (E)) {
4347
4351
// For an if/switch expression, produce a tailored warning.
4348
4352
Ctx.Diags .diagnose (E->getUnsafeLoc (),
@@ -4351,6 +4355,7 @@ class CheckEffectsCoverage : public EffectsHandlingWalker<CheckEffectsCoverage>
4351
4355
.highlight (E->getUnsafeLoc ());
4352
4356
return ;
4353
4357
}
4358
+
4354
4359
Ctx.Diags .diagnose (E->getUnsafeLoc (), diag::no_unsafe_in_unsafe);
4355
4360
}
4356
4361
Original file line number Diff line number Diff line change
1
+ // RUN: %target-typecheck-verify-swift -print-diagnostic-groups
2
+
3
+ @unsafe func unsafeFunc( ) { }
4
+
5
+ @unsafe
6
+ struct UnsafeType { }
7
+
8
+ protocol P { }
9
+
10
+ struct X : @unsafe P { }
11
+
12
+ func acceptP< T: P > ( _: T ) { }
13
+
14
+ func testItAll( ut: UnsafeType , x: X , i: Int ) {
15
+ _ = unsafe ut
16
+ unsafe acceptP( x)
17
+ _ = unsafe i
18
+ }
You can’t perform that action at this time.
0 commit comments