diff mbox series

[Ada] Don't check No_Wide_Characters restriction for illegal types

Message ID 20210617143311.GA10175@adacore.com
State New
Headers show
Series [Ada] Don't check No_Wide_Characters restriction for illegal types | expand

Commit Message

Pierre-Marie de Rodat June 17, 2021, 2:33 p.m. UTC
On illegal declarations of illegal types, e.g.:

   type X;
   type X is new X;

the No_Wide_Characters restriction was checked using an incomplete
entity of type X, which caused a crash.

Now restriction No_Wide_Characters in derived types is checked after the
legality of the parent type has been established.

Also, by moving the call to Check_Wide_Character_Restriction out of
Find_Type_Of_Subtype_Indic, we don't check this restriction on types
from the interface list. This is safe, because wide character types are
not allowed in the interface list anyway (as they are not tagged).

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

gcc/ada/

	* sem_ch3.adb (Analyze_Private_Extension_Declaration): Check
	No_Wide_Characters restriction after rejecting illegal parent
	types.
	(Derived_Type_Declaration): Likewise.
	(Find_Type_Of_Subtype_Indic): Remove check for
	No_Wide_Characters restriction, which was done too early.
diff mbox series

Patch

diff --git a/gcc/ada/sem_ch3.adb b/gcc/ada/sem_ch3.adb
--- a/gcc/ada/sem_ch3.adb
+++ b/gcc/ada/sem_ch3.adb
@@ -5121,6 +5121,8 @@  package body Sem_Ch3 is
          goto Leave;
       end if;
 
+      Check_Wide_Character_Restriction (Parent_Type, Indic);
+
       --  Perhaps the parent type should be changed to the class-wide type's
       --  specific type in this case to prevent cascading errors ???
 
@@ -17120,6 +17122,8 @@  package body Sem_Ch3 is
          Error_Msg_N ("null exclusion can only apply to an access type", N);
       end if;
 
+      Check_Wide_Character_Restriction (Parent_Type, Indic);
+
       --  Avoid deriving parent primitives of underlying record views
 
       Build_Derived_Type (N, Parent_Type, T, Is_Completion,
@@ -17979,10 +17983,6 @@  package body Sem_Ch3 is
          Typ := Entity (S);
       end if;
 
-      --  Check No_Wide_Characters restriction
-
-      Check_Wide_Character_Restriction (Typ, S);
-
       return Typ;
    end Find_Type_Of_Subtype_Indic;