* [Ada] Vectors: spurious error in -gnatwE mode
@ 2018-05-23 10:34 Pierre-Marie de Rodat
0 siblings, 0 replies; only message in thread
From: Pierre-Marie de Rodat @ 2018-05-23 10:34 UTC (permalink / raw)
To: gcc-patches; +Cc: Bob Duff
[-- Attachment #1: Type: text/plain, Size: 829 bytes --]
This patch fixes a bug in which if Ada.Containers.Vectors is instantiated with
an Index_Type such that Index_Type'Base'Last is less than Count_Type'Last, and
the -gnatwE switch is used, the compiler gives spurious error messages.
The following test should compile quietly with -gnatwE:
gnatmake short_vectors.ads -gnatwa -gnatwE -gnatf
with Ada.Containers.Vectors;
package Short_Vectors is
type Index_Type is range 1 .. 256;
package Map_Pkg is new Ada.Containers.Vectors
(Index_Type => Index_Type,
Element_Type => Integer);
end Short_Vectors;
Tested on x86_64-pc-linux-gnu, committed on trunk
2018-05-23 Bob Duff <duff@adacore.com>
gcc/ada/
* libgnat/a-convec.adb: (Insert, Insert_Space): Suppress warnings. The
code in question is not reachable in the case where Count_Type'Last is
out of range.
[-- Attachment #2: patch.diff --]
[-- Type: text/x-diff, Size: 1227 bytes --]
--- gcc/ada/libgnat/a-convec.adb
+++ gcc/ada/libgnat/a-convec.adb
@@ -999,9 +999,12 @@ package body Ada.Containers.Vectors is
-- We know that No_Index (the same as Index_Type'First - 1) is
-- less than 0, so it is safe to compute the following sum without
- -- fear of overflow.
+ -- fear of overflow. We need to suppress warnings, because
+ -- otherwise we get an error in -gnatwE mode.
+ pragma Warnings (Off);
Index := No_Index + Index_Type'Base (Count_Type'Last);
+ pragma Warnings (On);
if Index <= Index_Type'Last then
@@ -1657,9 +1660,12 @@ package body Ada.Containers.Vectors is
-- We know that No_Index (the same as Index_Type'First - 1) is
-- less than 0, so it is safe to compute the following sum without
- -- fear of overflow.
+ -- fear of overflow. We need to suppress warnings, because
+ -- otherwise we get an error in -gnatwE mode.
+ pragma Warnings (Off);
Index := No_Index + Index_Type'Base (Count_Type'Last);
+ pragma Warnings (On);
if Index <= Index_Type'Last then
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2018-05-23 10:34 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-05-23 10:34 [Ada] Vectors: spurious error in -gnatwE mode Pierre-Marie de Rodat
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).