diff mbox series

[Ada] Detect illegal implicit type conversions

Message ID 20191213095501.GA14007@adacore.com
State New
Headers show
Series [Ada] Detect illegal implicit type conversions | expand

Commit Message

Pierre-Marie de Rodat Dec. 13, 2019, 9:55 a.m. UTC
When testing whether the target of a type conversion is a general access
type, the test should not be

   E_Kind (Target_Type) = E_General_Access_Type

but rather

   E_Kind (Base_Type (Target_Type)) = E_General_Access_Type

Fix this bug in two places. As a consequence of these bugs, some of the
legality rules regarding conversions (implicit and explicit) to a
general access type were not being enforced in some cases when the
target of the conversion was something other than a first named subtype.

Tested on x86_64-pc-linux-gnu, committed on trunk

2019-12-13  Steve Baird  <baird@adacore.com>

gcc/ada/

	* sem_res.adb (Resolve, Valid_Conversion): Add Base_Type call
	when testing whether a type is a general access type.
diff mbox series

Patch

--- gcc/ada/sem_res.adb
+++ gcc/ada/sem_res.adb
@@ -3256,7 +3256,7 @@  package body Sem_Res is
          --  convert implicitly are allowed in membership tests).
 
          if Ada_Version >= Ada_2012
-           and then Ekind (Ctx_Type) = E_General_Access_Type
+           and then Ekind (Base_Type (Ctx_Type)) = E_General_Access_Type
            and then Ekind (Etype (N)) = E_Anonymous_Access_Type
            and then Nkind (Parent (N)) not in N_Membership_Test
          then
@@ -13328,7 +13328,7 @@  package body Sem_Res is
             if Ada_Version >= Ada_2012
               and then not Comes_From_Source (N)
               and then Is_Rewrite_Substitution (N)
-              and then Ekind (Target_Type) = E_General_Access_Type
+              and then Ekind (Base_Type (Target_Type)) = E_General_Access_Type
               and then Ekind (Opnd_Type) = E_Anonymous_Access_Type
             then
                if Is_Itype (Opnd_Type) then