aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSteve Baird <baird@adacore.com>2022-05-24 14:09:14 -0700
committerPierre-Marie de Rodat <derodat@adacore.com>2022-07-04 07:45:54 +0000
commitf7c05e82037356ac4610e9e5d1365b345a17d0f7 (patch)
treefcc31852c5d7045342defa872ea420dc03c937cf
parente7428fff12ca000b59185c71dee511ac0c886089 (diff)
downloadgcc-f7c05e82037356ac4610e9e5d1365b345a17d0f7.zip
gcc-f7c05e82037356ac4610e9e5d1365b345a17d0f7.tar.gz
gcc-f7c05e82037356ac4610e9e5d1365b345a17d0f7.tar.bz2
[Ada] Avoid unwanted warnings for statically-known-successful assertions
The -gnatwc switch enables warnings for test condition outcomes that are known at compile time. Such warnings are unlikely to be useful in the case of an assertion expression (or a subexpression thereof), so do not generate them in that case. gcc/ada/ * sem_warn.adb (Warn_On_Constant_Valid_Condition): Do not generate a warning if the expression in question is an assertion expression, or a subexpression thereof. But do call Test_Comparison so that it can generate warnings for the cases that it generates warnings for. * sem_prag.ads: Modify Assertion_Expression_Pragma constant so that the predicate Sem_Util.In_Assertion_Expression_Pragma returns True for the expression of a Compile_Time_Error pragma.
-rw-r--r--gcc/ada/sem_prag.ads1
-rw-r--r--gcc/ada/sem_warn.adb9
2 files changed, 8 insertions, 2 deletions
diff --git a/gcc/ada/sem_prag.ads b/gcc/ada/sem_prag.ads
index 0a1ad5b..e8a65ce 100644
--- a/gcc/ada/sem_prag.ads
+++ b/gcc/ada/sem_prag.ads
@@ -135,6 +135,7 @@ package Sem_Prag is
Pragma_Assert_And_Cut => True,
Pragma_Assume => True,
Pragma_Check => True,
+ Pragma_Compile_Time_Error => True,
Pragma_Contract_Cases => True,
Pragma_Default_Initial_Condition => True,
Pragma_Initial_Condition => True,
diff --git a/gcc/ada/sem_warn.adb b/gcc/ada/sem_warn.adb
index b23be72..1d73f21 100644
--- a/gcc/ada/sem_warn.adb
+++ b/gcc/ada/sem_warn.adb
@@ -3401,9 +3401,14 @@ package body Sem_Warn is
False_Result => False_Result);
-- Warn on a possible evaluation to False / True in the presence of
- -- invalid values.
+ -- invalid values. But issue no warning for an assertion expression
+ -- (or a subexpression thereof); in particular, we don't want a
+ -- warning about an assertion that will always succeed.
- if True_Result then
+ if In_Assertion_Expression_Pragma (Op) then
+ null;
+
+ elsif True_Result then
Error_Msg_N
("condition can only be False if invalid values present?c?", Op);