]> gcc.gnu.org Git - gcc.git/commit
d: Ensure casting from bool results in either 0 or 1 (PR96435)
authorIain Buclaw <ibuclaw@gdcproject.org>
Mon, 26 Jul 2021 17:28:02 +0000 (19:28 +0200)
committerIain Buclaw <ibuclaw@gdcproject.org>
Thu, 29 Jul 2021 14:16:19 +0000 (16:16 +0200)
commit5c9b7408dc578cb2ae142a5c1b724c183497bdb2
tree9d66585f4b9e8f11d44c05275ea7016577471721
parent75f2e3f6cbbb79421b12e399498e9c14241359e7
d: Ensure casting from bool results in either 0 or 1 (PR96435)

If casting from bool, the result is either 0 or 1, any other value
violates @safe code, so enforce that it is never invalid.

PR d/96435

gcc/d/ChangeLog:

* d-convert.cc (convert_for_rvalue): New function.
* d-tree.h (convert_for_rvalue): Declare.
* expr.cc (ExprVisitor::visit (CastExp *)): Use convert_for_rvalue.
(build_return_dtor): Likewise.

gcc/testsuite/ChangeLog:

* gdc.dg/torture/pr96435.d: New test.
gcc/d/d-convert.cc
gcc/d/d-tree.h
gcc/d/expr.cc
gcc/testsuite/gdc.dg/torture/pr96435.d [new file with mode: 0644]
This page took 0.068623 seconds and 6 git commands to generate.