mirror of
https://github.com/dlang/dmd.git
synced 2025-04-26 05:00:16 +03:00
[Deprecation -> Error] nothrow function contracts that throw (#16801)
This commit is contained in:
parent
a271bd1847
commit
0834c750aa
3 changed files with 21 additions and 11 deletions
17
changelog/dmd.deprecation-throwing-contracts.dd
Normal file
17
changelog/dmd.deprecation-throwing-contracts.dd
Normal file
|
@ -0,0 +1,17 @@
|
|||
An error is now issued for `in`/`out` contracts of `nothrow` functions that may throw
|
||||
|
||||
This used to issue a deprecation, it is now an error:
|
||||
```
|
||||
void test() nothrow
|
||||
in
|
||||
{
|
||||
throw new Exception(null); // Error: `in` contract may throw but function is marked as `nothrow`
|
||||
}
|
||||
out
|
||||
{
|
||||
throw new Exception(null); // Error: `out` contract may throw but function is marked as `nothrow`
|
||||
}
|
||||
do
|
||||
{
|
||||
}
|
||||
```
|
|
@ -1009,14 +1009,11 @@ private extern(C++) final class Semantic3Visitor : Visitor
|
|||
// BUG: verify that all in and ref parameters are read
|
||||
freq = freq.statementSemantic(sc2);
|
||||
|
||||
// @@@DEPRECATED_2.111@@@ - pass `isnothrow` instead of `false` to print a more detailed error msg`
|
||||
const blockExit = freq.blockExit(funcdecl, null);
|
||||
if (blockExit & BE.throw_)
|
||||
{
|
||||
if (isnothrow)
|
||||
// @@@DEPRECATED_2.111@@@
|
||||
// Deprecated in 2.101, can be made an error in 2.111
|
||||
deprecation(funcdecl.loc, "`%s`: `in` contract may throw but function is marked as `nothrow`",
|
||||
error(funcdecl.loc, "`%s`: `in` contract may throw but function is marked as `nothrow`",
|
||||
funcdecl.toPrettyChars());
|
||||
else if (funcdecl.nothrowInprocess)
|
||||
f.isnothrow = false;
|
||||
|
@ -1056,14 +1053,11 @@ private extern(C++) final class Semantic3Visitor : Visitor
|
|||
|
||||
fens = fens.statementSemantic(sc2);
|
||||
|
||||
// @@@DEPRECATED_2.111@@@ - pass `isnothrow` instead of `false` to print a more detailed error msg`
|
||||
const blockExit = fens.blockExit(funcdecl, null);
|
||||
if (blockExit & BE.throw_)
|
||||
{
|
||||
if (isnothrow)
|
||||
// @@@DEPRECATED_2.111@@@
|
||||
// Deprecated in 2.101, can be made an error in 2.111
|
||||
deprecation(funcdecl.loc, "`%s`: `out` contract may throw but function is marked as `nothrow`",
|
||||
error(funcdecl.loc, "`%s`: `out` contract may throw but function is marked as `nothrow`",
|
||||
funcdecl.toPrettyChars());
|
||||
else if (funcdecl.nothrowInprocess)
|
||||
f.isnothrow = false;
|
||||
|
|
|
@ -1,9 +1,8 @@
|
|||
// REQUIRED_ARGS: -de
|
||||
/*
|
||||
TEST_OUTPUT:
|
||||
---
|
||||
fail_compilation/fail13123.d(10): Deprecation: `fail13123.test`: `in` contract may throw but function is marked as `nothrow`
|
||||
fail_compilation/fail13123.d(10): Deprecation: `fail13123.test`: `out` contract may throw but function is marked as `nothrow`
|
||||
fail_compilation/fail13123.d(9): Error: `fail13123.test`: `in` contract may throw but function is marked as `nothrow`
|
||||
fail_compilation/fail13123.d(9): Error: `fail13123.test`: `out` contract may throw but function is marked as `nothrow`
|
||||
---
|
||||
*/
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue