ada: Emit warnings for (some) ineffective static predicate tests
commita3594ab9646e083eb0e5984907285f6f2162eeea
authorSteve Baird <baird@adacore.com>
Fri, 16 Dec 2022 00:50:05 +0000 (15 16:50 -0800)
committerMarc Poulhiès <poulhies@adacore.com>
Mon, 15 May 2023 09:36:42 +0000 (15 11:36 +0200)
tree2e17aeb06f6cfc5a13933dd56a1a59f2f5349316
parenta1f35b49196ca219863cc6e64eb1d1eb1483cca9
ada: Emit warnings for (some) ineffective static predicate tests

Generate a warning if a static predicate tests for a value that
does not belong to the parent subtype. For example, in
  subtype S is Positive with Static_Predicate => S not in 0 | 11 | 222;
the 0 is ineffective because Positive already excludes that value.
Generation of this new warning is controlled by the -gnatw_s switch,
which can also be enabled via -gnatwa.

gcc/ada/

* warnsw.ads: Add a new element,
Warn_On_Ineffective_Predicate_Test, to the Opt_Warnings_Enum
enumeration type.
* warnsw.adb: Bind "-gnatw_s" to the new
Warn_On_Ineffective_Predicate_Test switch. Add the new switch to
the set of switches enabled by -gnata .
* sem_ch13.adb
(Build_Discrete_Static_Predicate): Declare new local procedure,
Warn_If_Test_Ineffective, which conditionally generates new
warning. Call this new procedure when building a new element of an
RList.
* doc/gnat_ugn/building_executable_programs_with_gnat.rst:
Document the -gnatw_s switch (and the corresponding -gnatw_S
switch).
* gnat_ugn.texi: Regenerate.
gcc/ada/doc/gnat_ugn/building_executable_programs_with_gnat.rst
gcc/ada/gnat_ugn.texi
gcc/ada/sem_ch13.adb
gcc/ada/warnsw.adb
gcc/ada/warnsw.ads