]> 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 15:21:36 +0000 (17:21 +0200)
commitc848c0ec7fab0c0a220683ad234c8842939941cf
tree2a62fe2f310d60db1ff5f20900f32da15021bd19
parent64b7e66c1a86cf880a43c0e31375bb74f15562f3
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/pr96435.d: New test.

(cherry picked from commit 5c9b7408dc578cb2ae142a5c1b724c183497bdb2)
gcc/d/d-convert.cc
gcc/d/d-tree.h
gcc/d/expr.cc
gcc/testsuite/gdc.dg/pr96435.d [new file with mode: 0644]
This page took 0.060854 seconds and 6 git commands to generate.