Commit ad277369 by Ed Schonberg Committed by Pierre-Marie de Rodat

[Ada] Remove misleading warning/suggestion in membership test

This patch removes a warning on a membership test whose right operand is
given by a range. In many cases the check can be replaced by the use of
attribute 'Valid, but if the bounds of range are type conversion this
replacement would be invorrect and the warning and suggestion are
misleading.

2019-07-22  Ed Schonberg  <schonberg@adacore.com>

gcc/ada/

	* exp_ch4.adb (Expand_N_In): Do not suggest the use of attribute
	'Valid as a replacement for a range check on a discrete type
	when the bounds of the range are given by type conversions,
	because in such a case there are distinct types involved and the
	subbested attribute replacement would be misplaced.

gcc/testsuite/

	* gnat.dg/warn26.adb: New testcase.

From-SVN: r273694
parent a2119175
2019-07-22 Ed Schonberg <schonberg@adacore.com>
* exp_ch4.adb (Expand_N_In): Do not suggest the use of attribute
'Valid as a replacement for a range check on a discrete type
when the bounds of the range are given by type conversions,
because in such a case there are distinct types involved and the
subbested attribute replacement would be misplaced.
2019-07-22 Yannick Moy <moy@adacore.com>
* sem_spark.adb (Get_Root_Object, Is_Path_Expression,
......
......@@ -6272,6 +6272,10 @@ package body Exp_Ch4 is
-- Similarly, do not rewrite membership as a validity check if
-- within the predicate function for the type.
-- Finally, if the original bounds are type conversions, even
-- if they have been folded into constants, there are different
-- types involved and 'Valid is not appropriate.
then
if In_Instance
or else (Ekind (Current_Scope) = E_Function
......@@ -6279,6 +6283,11 @@ package body Exp_Ch4 is
then
null;
elsif Nkind (Lo_Orig) = N_Type_Conversion
or else Nkind (Hi_Orig) = N_Type_Conversion
then
null;
else
Substitute_Valid_Check;
goto Leave;
......
2019-07-22 Ed Schonberg <schonberg@adacore.com>
* gnat.dg/warn26.adb: New testcase.
2019-07-22 Javier Miranda <miranda@adacore.com>
* gnat.dg/class_wide5.adb: New testcase.
......
-- { dg-do compile }
procedure Warn26 is
Monitor_Period_Min : constant := 5;
Monitor_Period_Max : constant := 30;
type Monitor_Period is range Monitor_Period_Min .. Monitor_Period_Max;
subtype Period_T is Positive range 5 .. 30;
function Id (X : Period_T) return Period_T is (X);
Input_Period : Period_T := Id (20);
begin
if Input_Period in
Integer (Monitor_Period'First) .. Integer ( Monitor_Period'Last)
then
null;
end if;
end Warn26;
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment