[Ada] Avoid uninitialized variable in bounded containers
authorBob Duff <duff@adacore.com>
Wed, 18 Sep 2019 08:31:37 +0000 (08:31 +0000)
committerPierre-Marie de Rodat <pmderodat@gcc.gnu.org>
Wed, 18 Sep 2019 08:31:37 +0000 (08:31 +0000)
commit5ce1c7733b720d583eb46910e738adc932ecf7ce
treed58bde07e155171f6e90491b6562ad3421b4c2af
parent2b6cd962513387303661614b292397cb6432590c
[Ada] Avoid uninitialized variable in bounded containers

In function Copy in Ada.Containers.Bounded_Ordered_Sets and other
bounded containers packages, remove a possible use of an uninitialized
variable. This was not a bug, because the uninitialized variable could
be used only if checks are suppressed, and the checks would have failed,
leading to erroneous execution.

However, it seems more robust this way, and is probably equally
efficient, and avoids a warning that is given if checks are suppressed,
and the -Wall switch is given, and optimization is turned on.

2019-09-18  Bob Duff  <duff@adacore.com>

gcc/ada/

* libgnat/a-cbhama.adb, libgnat/a-cbhase.adb,
libgnat/a-cbmutr.adb, libgnat/a-cborma.adb,
libgnat/a-cborse.adb, libgnat/a-cobove.adb (Copy): Avoid reading
the uninitialized variable C in the Checks = False case. Change
variable to be a constant.

gcc/testsuite/

* gnat.dg/containers1.adb, gnat.dg/containers1.ads: New
testcase.

From-SVN: r275839
gcc/ada/ChangeLog
gcc/ada/libgnat/a-cbhama.adb
gcc/ada/libgnat/a-cbhase.adb
gcc/ada/libgnat/a-cbmutr.adb
gcc/ada/libgnat/a-cborma.adb
gcc/ada/libgnat/a-cborse.adb
gcc/ada/libgnat/a-cobove.adb
gcc/testsuite/ChangeLog
gcc/testsuite/gnat.dg/containers1.adb [new file with mode: 0644]
gcc/testsuite/gnat.dg/containers1.ads [new file with mode: 0644]