mirror of
https://github.com/dlang/dmd.git
synced 2025-04-27 21:51:03 +03:00
make new safety checks warnings when using default feature setting (#15411)
This commit is contained in:
parent
634b05bc0e
commit
a699cf9803
5 changed files with 21 additions and 19 deletions
|
@ -4606,6 +4606,7 @@ bool setUnsafe(Scope* sc,
|
||||||
bool setUnsafePreview(Scope* sc, FeatureState fs, bool gag, Loc loc, const(char)* msg,
|
bool setUnsafePreview(Scope* sc, FeatureState fs, bool gag, Loc loc, const(char)* msg,
|
||||||
RootObject arg0 = null, RootObject arg1 = null, RootObject arg2 = null)
|
RootObject arg0 = null, RootObject arg1 = null, RootObject arg2 = null)
|
||||||
{
|
{
|
||||||
|
//printf("setUnsafePreview() fs:%d %s\n", fs, msg);
|
||||||
with (FeatureState) final switch (fs)
|
with (FeatureState) final switch (fs)
|
||||||
{
|
{
|
||||||
case disabled:
|
case disabled:
|
||||||
|
@ -4620,9 +4621,10 @@ bool setUnsafePreview(Scope* sc, FeatureState fs, bool gag, Loc loc, const(char)
|
||||||
if (sc.func.isSafeBypassingInference())
|
if (sc.func.isSafeBypassingInference())
|
||||||
{
|
{
|
||||||
if (!gag)
|
if (!gag)
|
||||||
previewErrorFunc(sc.isDeprecated(), fs)(
|
{
|
||||||
loc, msg, arg0 ? arg0.toChars() : "", arg1 ? arg1.toChars() : "", arg2 ? arg2.toChars() : ""
|
if (!sc.isDeprecated() && global.params.obsolete)
|
||||||
);
|
warning(loc, msg, arg0 ? arg0.toChars() : "", arg1 ? arg1.toChars() : "", arg2 ? arg2.toChars() : "");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else if (!sc.func.safetyViolation)
|
else if (!sc.func.safetyViolation)
|
||||||
{
|
{
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
REQUIRED_ARGS: -de
|
REQUIRED_ARGS: -de -wo
|
||||||
TEST_OUTPUT:
|
TEST_OUTPUT:
|
||||||
---
|
---
|
||||||
fail_compilation/dip1000_deprecation.d(20): Deprecation: `@safe` function `main` calling `inferred`
|
fail_compilation/dip1000_deprecation.d(20): Deprecation: `@safe` function `main` calling `inferred`
|
||||||
|
@ -9,17 +9,17 @@ fail_compilation/dip1000_deprecation.d(22): Deprecation: `@safe` function `main`
|
||||||
fail_compilation/dip1000_deprecation.d(39): which calls `dip1000_deprecation.inferred`
|
fail_compilation/dip1000_deprecation.d(39): which calls `dip1000_deprecation.inferred`
|
||||||
fail_compilation/dip1000_deprecation.d(28): which wouldn't be `@safe` because of:
|
fail_compilation/dip1000_deprecation.d(28): which wouldn't be `@safe` because of:
|
||||||
fail_compilation/dip1000_deprecation.d(28): scope variable `x0` may not be returned
|
fail_compilation/dip1000_deprecation.d(28): scope variable `x0` may not be returned
|
||||||
fail_compilation/dip1000_deprecation.d(54): Deprecation: escaping reference to stack allocated value returned by `S(null)`
|
fail_compilation/dip1000_deprecation.d(54): Warning: escaping reference to stack allocated value returned by `S(null)`
|
||||||
fail_compilation/dip1000_deprecation.d(55): Deprecation: escaping reference to stack allocated value returned by `createS()`
|
fail_compilation/dip1000_deprecation.d(55): Warning: escaping reference to stack allocated value returned by `createS()`
|
||||||
fail_compilation/dip1000_deprecation.d(58): Deprecation: returning `s.incorrectReturnRef()` escapes a reference to local variable `s`
|
fail_compilation/dip1000_deprecation.d(58): Warning: returning `s.incorrectReturnRef()` escapes a reference to local variable `s`
|
||||||
---
|
---
|
||||||
*/
|
*/
|
||||||
|
|
||||||
void main() @safe
|
void main() @safe
|
||||||
{
|
{
|
||||||
inferred();
|
cast(void)inferred();
|
||||||
inferredB(); // no deprecation, trusted
|
cast(void)inferredB(); // no deprecation, trusted
|
||||||
inferredC(); // nested deprecation
|
cast(void)inferredC(); // nested deprecation
|
||||||
}
|
}
|
||||||
|
|
||||||
auto inferred()
|
auto inferred()
|
||||||
|
@ -49,10 +49,10 @@ struct S
|
||||||
|
|
||||||
S createS() { return S.init; }
|
S createS() { return S.init; }
|
||||||
|
|
||||||
int* escape()
|
int* escape(int i)
|
||||||
{
|
{
|
||||||
return S().incorrectReturnRef();
|
if (i) return S().incorrectReturnRef();
|
||||||
return createS().incorrectReturnRef();
|
if (i) return createS().incorrectReturnRef();
|
||||||
|
|
||||||
S s;
|
S s;
|
||||||
return s.incorrectReturnRef();
|
return s.incorrectReturnRef();
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
REQUIRED_ARGS:
|
REQUIRED_ARGS: -wo
|
||||||
TEST_OUTPUT:
|
TEST_OUTPUT:
|
||||||
---
|
---
|
||||||
fail_compilation/fail_scope.d(30): Deprecation: scope parameter `da` may not be returned
|
fail_compilation/fail_scope.d(30): Deprecation: scope parameter `da` may not be returned
|
||||||
|
@ -16,7 +16,7 @@ fail_compilation/fail_scope.d(82): Error: returning `& string` escapes a referen
|
||||||
fail_compilation/fail_scope.d(92): Error: returning `cast(int[])a` escapes a reference to local variable `a`
|
fail_compilation/fail_scope.d(92): Error: returning `cast(int[])a` escapes a reference to local variable `a`
|
||||||
fail_compilation/fail_scope.d(100): Error: returning `cast(int[])a` escapes a reference to local variable `a`
|
fail_compilation/fail_scope.d(100): Error: returning `cast(int[])a` escapes a reference to local variable `a`
|
||||||
fail_compilation/fail_scope.d(108): Error: escaping reference to outer local variable `x`
|
fail_compilation/fail_scope.d(108): Error: escaping reference to outer local variable `x`
|
||||||
fail_compilation/fail_scope.d(127): Deprecation: returning `s.bar()` escapes a reference to local variable `s`
|
fail_compilation/fail_scope.d(127): Warning: returning `s.bar()` escapes a reference to local variable `s`
|
||||||
fail_compilation/fail_scope.d(137): Error: returning `foo16226(i)` escapes a reference to local variable `i`
|
fail_compilation/fail_scope.d(137): Error: returning `foo16226(i)` escapes a reference to local variable `i`
|
||||||
---
|
---
|
||||||
//fail_compilation/fail_scope.d(35): Error: scope variable `da` may not be returned
|
//fail_compilation/fail_scope.d(35): Error: scope variable `da` may not be returned
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
/*
|
/* REQUIRED_ARGS: -wo
|
||||||
TEST_OUTPUT:
|
TEST_OUTPUT:
|
||||||
---
|
---
|
||||||
fail_compilation/test13536.d(23): Error: field `U.sysDg` cannot access pointers in `@safe` code that overlap other fields
|
fail_compilation/test13536.d(23): Error: field `U.sysDg` cannot access pointers in `@safe` code that overlap other fields
|
||||||
fail_compilation/test13536.d(23): Deprecation: address of variable `s` assigned to `u` with longer lifetime
|
fail_compilation/test13536.d(23): Warning: address of variable `s` assigned to `u` with longer lifetime
|
||||||
fail_compilation/test13536.d(24): Error: field `U.safeDg` cannot access pointers in `@safe` code that overlap other fields
|
fail_compilation/test13536.d(24): Error: field `U.safeDg` cannot access pointers in `@safe` code that overlap other fields
|
||||||
---
|
---
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -1,9 +1,9 @@
|
||||||
/*
|
/* REQUIRED_ARGS: -wo
|
||||||
TEST_OUTPUT:
|
TEST_OUTPUT:
|
||||||
---
|
---
|
||||||
fail_compilation/test16365.d(21): Error: `this` reference necessary to take address of member `f1` in `@safe` function `main`
|
fail_compilation/test16365.d(21): Error: `this` reference necessary to take address of member `f1` in `@safe` function `main`
|
||||||
fail_compilation/test16365.d(23): Error: cannot implicitly convert expression `&f2` of type `void delegate() pure nothrow @nogc @safe` to `void function() @safe`
|
fail_compilation/test16365.d(23): Error: cannot implicitly convert expression `&f2` of type `void delegate() pure nothrow @nogc @safe` to `void function() @safe`
|
||||||
fail_compilation/test16365.d(27): Deprecation: address of variable `s` assigned to `dg` with longer lifetime
|
fail_compilation/test16365.d(27): Warning: address of variable `s` assigned to `dg` with longer lifetime
|
||||||
fail_compilation/test16365.d(28): Error: `dg.funcptr` cannot be used in `@safe` code
|
fail_compilation/test16365.d(28): Error: `dg.funcptr` cannot be used in `@safe` code
|
||||||
---
|
---
|
||||||
*/
|
*/
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue