https://gcc.gnu.org/g:37ee107ddd833fd149f10af98259d75d6002da0a
commit r16-2012-g37ee107ddd833fd149f10af98259d75d6002da0a Author: Steve Baird <ba...@adacore.com> Date: Mon Jun 16 16:46:13 2025 -0700 ada: Do not generate incorrect warning about redundant type conversion If -gnatwr is enabled, then in some cases a type conversion between two different Boolean types incorrectly results in a warning that the conversion is redundant. gcc/ada/ChangeLog: * sem_res.adb (Resolve_Type_Conversion): Replace code for detecting a similar case with a more comprehensive test. Diff: --- gcc/ada/sem_res.adb | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/gcc/ada/sem_res.adb b/gcc/ada/sem_res.adb index 96e8da6b54e2..e44994a681d7 100644 --- a/gcc/ada/sem_res.adb +++ b/gcc/ada/sem_res.adb @@ -12463,16 +12463,6 @@ package body Sem_Res is Orig_N := Original_Node (Expression (Orig_N)); Orig_T := Target_Typ; - -- If the node is part of a larger expression, the Target_Type - -- may not be the original type of the node if the context is a - -- condition. Recover original type to see if conversion is needed. - - if Is_Boolean_Type (Orig_T) - and then Nkind (Parent (N)) in N_Op - then - Orig_T := Etype (Parent (N)); - end if; - -- If we have an entity name, then give the warning if the entity -- is the right type, or if it is a loop parameter covered by the -- original type (that's needed because loop parameters have an @@ -12548,6 +12538,16 @@ package body Sem_Res is then null; + -- Do not warn if original source-level conversion was + -- between two different types. + + elsif Nkind (Original_Node (N)) = N_Type_Conversion + and then + Base_Type (Etype (Subtype_Mark (Original_Node (N)))) + /= Base_Type (Etype (Expression (Original_Node (N)))) + then + null; + -- Here we give the redundant conversion warning. If it is an -- entity, give the name of the entity in the message. If not, -- just mention the expression.