-
-
Notifications
You must be signed in to change notification settings - Fork 607
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix Issue 24084 - Add -nothrow Switch to Compiler (#15536)
- Loading branch information
1 parent
705782a
commit 622a432
Showing
5 changed files
with
60 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
Add -nothrow Switch to Compiler | ||
|
||
dmd itself (and presumably others) do not throw Exceptions, preferring other methods | ||
for dealing with errors. There is a cost, however, in supporting Exceptions even when | ||
they are never thrown. The cost is in adding stack unwinders for things like RAII | ||
objects, and preventing numerous optimizations across try-catch boundaries. | ||
|
||
Adding `nothrow` to all the code in a project turns out to be an inordinate amount of | ||
work if the program is large. Putting `nothrow:` at the top of the module doesn't | ||
influence the status for member functions in a class or struct, the `nothrow:` | ||
will have to be repeated for each class/struct. | ||
|
||
Adding the -nothrow switch to the compiler causes the stack unwinders to not be added | ||
and enables the optimizations. This capability is already there for -betterC code, | ||
this would just enable it for regular D code. | ||
|
||
The switch does not affect semantic analysis, just the code generation. Name mangling | ||
is not affected. | ||
|
||
The switch is useful for determining what effect exception handling has on an executable's | ||
size and performance in non-throwing code. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
/* REQUIRED_ARGS: -nothrow | ||
* TEST_OUTPUT: | ||
--- | ||
fail_compilation/test24084.d(110): Error: cannot use `throw` statements with -nothrow | ||
fail_compilation/test24084.d(112): Error: cannot use try-catch statements with -nothrow | ||
--- | ||
*/ | ||
|
||
// https://issues.dlang.org/show_bug.cgi?id=24084 | ||
|
||
#line 100 | ||
|
||
struct S | ||
{ | ||
int x; | ||
~this() { } | ||
} | ||
|
||
void xyzzy() | ||
{ | ||
S s; | ||
throw new Exception("xx"); | ||
|
||
try | ||
{ | ||
int y; | ||
} catch (Exception) { } | ||
} |