]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
ada: Spurious error on class-wide preconditions
authorJavier Miranda <miranda@adacore.com>
Thu, 27 Jul 2023 11:02:20 +0000 (11:02 +0000)
committerMarc Poulhiès <poulhies@adacore.com>
Mon, 7 Aug 2023 11:14:35 +0000 (13:14 +0200)
The compiler reports an spurious error when a class-wide precondition
expression has a class-wide type conversion.

gcc/ada/

* sem_res.adb (Resolve_Type_Conversion): Do not warn on conversion
to class-wide type on internally build helpers of class-wide
preconditions.

gcc/ada/sem_res.adb

index d3a0192fb099f0c0068d614da5f63ebe8cc7f6ec..ac0c60f5f22df9f35b8aeb754c6b6c1f7b842cc7 100644 (file)
@@ -12455,6 +12455,18 @@ package body Sem_Res is
             elsif Orig_T = Base_Type (Standard_Long_Long_Integer) then
                null;
 
+            --  Do not warn on conversion to class-wide type on helpers of
+            --  class-wide preconditions because in this context the warning
+            --  would be spurious (since the class-wide precondition has been
+            --  installed in the return statement of the helper, which has a
+            --  class-wide formal type instead of a regular tagged type).
+
+            elsif Is_Class_Wide_Type (Orig_T)
+              and then Is_Subprogram_Or_Generic_Subprogram (Current_Scope)
+              and then Present (Class_Preconditions_Subprogram (Current_Scope))
+            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.