This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Ada] Spurious error with formal incomplete types


This patch fixes a spurious error on the use of of a generic unit with formal
incomplete types, as a formal package in another generic unit, when the
actuals for the incomplete types are themselves formal incomplete types.

The treatment of incomplete subtypes that are created for such formals is now
more consistent with the handling of other subtypes, given their increased
use in Ada2012.

The following must compile quietly:

---
   gcc -c promote_2_streams.ads
----

generic
   type Data_Stream_Type;
   type Data_Type;
   with function Has_Data
     (Stream : not null access Data_Stream_Type) return Boolean;
   with function Consume
     (Stream : not null access Data_Stream_Type) return Data_Type;
package Data_Streams is end;
---
with Data_Streams;
generic
  type Data1_Type is private;
  type Data2_Type is private;

  with package DS1 is new Data_Streams (Data_Type => Data1_Type, others => <>);
  with package DS2 is new Data_Streams (Data_Type => Data2_Type, others => <>);
package Promote_2_Streams is

   type Which_Type is range 1 .. 2;

   type Data_Type (Which : Which_Type := 1) is record
      case Which is
         when 1 => Data1 : Data1_Type;
         when 2 => Data2 : Data2_Type;
      end case;
   end record;

   function Consume1 (Stream : not null access DS1.Data_Stream_Type)
     return Data_Type is ((Which => 1, Data1 => DS1.Consume (Stream)));

   function Consume2 (Stream : not null access DS2.Data_Stream_Type)
     return Data_Type is ((Which => 2, Data2 => DS2.Consume (Stream)));

   package PS1 is new Data_Streams
     (DS1.Data_Stream_Type, Data_Type, DS1.Has_Data, Consume1);

   package PS2 is new Data_Streams
     (DS2.Data_Stream_Type, Data_Type, DS2.Has_Data, Consume2);

end Promote_2_Streams;

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

2017-09-06  Ed Schonberg  <schonberg@adacore.com>

	* einfo.adb (Designated_Type): Use Is_Incomplete_Type to handle
	properly incomplete subtypes that may be created by explicit or
	implicit declarations.
	(Is_Base_Type): Take E_Incomplete_Subtype into account.
	(Subtype_Kind): Ditto.
	* sem_ch3.adb (Build_Discriminated_Subtype): Set properly the
	Ekind of a subtype of a discriminated incomplete type.
	(Fixup_Bad_Constraint): Use Subtype_Kind in all cases, including
	incomplete types, to preserve error reporting.
	(Process_Incomplete_Dependents): Do not create a subtype
	declaration for an incomplete subtype that is created internally.
	* sem_ch7.adb (Analyze_Package_Specification): Handle properly
	incomplete subtypes that do not require a completion, either
	because they are limited views, of they are generic actuals.

Attachment: difs
Description: Text document


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]