aboutsummaryrefslogtreecommitdiff
path: root/gcc/ada/sem_res.adb
diff options
context:
space:
mode:
authorBob Duff <duff@adacore.com>2021-12-10 06:01:22 -0500
committerPierre-Marie de Rodat <derodat@adacore.com>2022-01-06 17:11:42 +0000
commit2a60c08e98acaae212840b2d3329b5bd13778581 (patch)
tree2b00cc1deb87a7f7e19d77777f72e98726150e5e /gcc/ada/sem_res.adb
parent1871f2cb3cef93485a11057b1bb9aff2c68dd512 (diff)
downloadgcc-2a60c08e98acaae212840b2d3329b5bd13778581.zip
gcc-2a60c08e98acaae212840b2d3329b5bd13778581.tar.gz
gcc-2a60c08e98acaae212840b2d3329b5bd13778581.tar.bz2
[Ada] Warn on subtype declaration of null range
gcc/ada/ * sem_res.adb (Resolve_Range): Warn on null range, unless we are inside a generic unit or an instance thereof. * sem_ch3.adb (Analyze_Subtype_Indication): Minor: avoid double negative.
Diffstat (limited to 'gcc/ada/sem_res.adb')
-rw-r--r--gcc/ada/sem_res.adb24
1 files changed, 24 insertions, 0 deletions
diff --git a/gcc/ada/sem_res.adb b/gcc/ada/sem_res.adb
index 9a63506..44b0414 100644
--- a/gcc/ada/sem_res.adb
+++ b/gcc/ada/sem_res.adb
@@ -10754,6 +10754,30 @@ package body Sem_Res is
Fold_Uint (H, Expr_Value (H), Static => True);
end if;
end if;
+
+ -- If we have a compile-time-known null range, we warn, because that is
+ -- likely to be a mistake. (Dynamic null ranges make sense, but often
+ -- compile-time-known ones do not.) Warn only if this is in a subtype
+ -- declaration. We do this here, rather than while analyzing a subtype
+ -- declaration, in case we decide to expand the cases. We do not want to
+ -- warn in all cases, because some are idiomatic, such as an empty
+ -- aggregate (1 .. 0 => <>).
+
+ -- We don't warn in generics or their instances, because there might be
+ -- some instances where the range is null, and some where it is not,
+ -- which would lead to false alarms.
+
+ if not (Inside_A_Generic or In_Instance)
+ and then Comes_From_Source (N)
+ and then Compile_Time_Compare
+ (Low_Bound (N), High_Bound (N), Assume_Valid => True) = GT
+ and then Nkind (Parent (N)) = N_Range_Constraint
+ and then Nkind (Parent (Parent (N))) = N_Subtype_Indication
+ and then Nkind (Parent (Parent (Parent (N)))) = N_Subtype_Declaration
+ and then Is_OK_Static_Range (N)
+ then
+ Error_Msg_N ("null range??", N);
+ end if;
end Resolve_Range;
--------------------------