diff mbox series

[Ada] Missing error on non-limited derived type with limited component

Message ID 20180926092408.GA125650@adacore.com
State New
Headers show
Series [Ada] Missing error on non-limited derived type with limited component | expand

Commit Message

Pierre-Marie de Rodat Sept. 26, 2018, 9:24 a.m. UTC
This patch fixes a missing error on a type extension with limited
components, when the parent type is a derived limited interface. This
may allow the unit to improperly compile, but may lead to bind-time
errors when compiling a client of that unit.

Compiling p.adb must yield:

 keys.ads:8:06: extension of nonlimited type cannot have limited components
 keys.ads:8:06: limitedness is not inherited from limited interface
 keys.ads:8:06: add "limited" to type indication

----
with Keys;
procedure P is
begin
  null;
end;
----
with GNAT.Semaphores;
package Keys is

  type Ref0 is limited interface;
  type Ref2 is limited interface and Ref0;

  type Object is new Ref2 with record
     Lock : aliased GNAT.Semaphores.Binary_Semaphore
       (True, GNAT.Semaphores.Default_Ceiling);
  end record;

end;

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

2018-09-26  Ed Schonberg  <schonberg@adacore.com>

gcc/ada/

	* sem_ch3.adb (Is_Onown_Limited): A derived type whose parent P
	is a derived limited record is not itself limited if P is a
	derived limited interface.
diff mbox series

Patch

--- gcc/ada/sem_ch3.adb
+++ gcc/ada/sem_ch3.adb
@@ -1928,9 +1928,12 @@  package body Sem_Ch3 is
             return True;
 
          --  Else the type may have a limited interface progenitor, but a
-         --  limited record parent.
+         --  limited record parent that is not an interface.
 
-         elsif R /= P and then Is_Limited_Record (P) then
+         elsif R /= P
+            and then Is_Limited_Record (P)
+            and then not Is_Interface (P)
+         then
             return True;
 
          else