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 unqualified aggregate in instantiation.


When an aggregate appears without an explicit qualification in a generic
unit, the compiler builds a qualified expression for it, using the type of
the aggregate and when possible the scope of that type, so that both of
these entities are properly resolved in an instantiation. This patch verifies
that the scope is not hidden by a local declaration, to preent a spurious
visibility error in an instance.

The following must compile quietly:

   gcc -c foo.adb

---
with Langkit_Support.Lexical_Env;

procedure Foo is
   package Envs is new Langkit_Support.Lexical_Env (Natural);
begin
   null;
end Foo;
---
generic
   type T is private;
package Langkit_Support.Lexical_Env is

   type Record_Type is record
      V : T;
   end record;

   type Lexical_Env is null record;

   function Get
     (Self   : Lexical_Env;
      Value   : T;
      Filter : access function (R : Record_Type; Env : Lexical_Env)
                                return Boolean := null)
      return Boolean;

end Langkit_Support.Lexical_Env;
---
package body Langkit_Support.Lexical_Env is

   function Get
     (Self   : Lexical_Env;
      Value  : T;
      Filter : access function (R : Record_Type; Env : Lexical_Env)
                                return Boolean := null)
      return Boolean
   is
      Filtered_Out : constant Boolean :=
         Filter /= null
         and then not Filter ((V => Value), Self);
   begin
      return Filtered_Out;
   end Get;

end Langkit_Support.Lexical_Env;

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

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

	* sem_ch12.adb (Save_References_In_Aggregate): When constructing a
	qualified exxpression for an aggregate in a generic unit, verify that
	the scope of the type is itself visible and not hidden, so that the
	qualified expression is correctly resolved in any instance.

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]