comp.lang.ada
 help / color / mirror / Atom feed
From: joakimds@kth.se
Subject: Why forbid local generic instantiations?
Date: Fri, 25 Jan 2019 01:43:29 -0800 (PST)
Date: 2019-01-25T01:43:29-08:00	[thread overview]
Message-ID: <100ce3ee-71f7-46c7-a24c-dc9c0d280c4f@googlegroups.com> (raw)

Hi!

Consider the following code:

procedure Main is
   package Integer_Vectors is new Ada.Containers.Vectors (Positive, Integer);
begin
   null;
end Main;

It has a generic package instantiation local to the subprogram Main and not defined on package level. Both in AdaControl and GNATCheck there are rules to forbid local generic instantiations.

For example GNATCheck:
23.7.25 Generics_In_Subprograms

 Flag each declaration of a generic unit in a subprogram. Generic declarations in the bodies of generic subprograms are also flagged. A generic unit nested in another generic unit is not flagged. If a generic unit is declared in a local package that is declared in a subprogram body, the generic unit is flagged. 

This rule has no parameters.




Using AdaControl one can use the following rule to detect insantiations of generic packages/subprograms:
5.10 Declarations

This rule controls usage of various kinds of declarations, possibly only those occurring at specified locations. 
...



Why is it considered bad practise to use local generic instantiations? Within the C++ Community, limiting the use of templates doesn't seem an issue. On the contrary, going all in with template metaprogramming is the norm.

Does local generic instantiations have a performance penalty? Is it something that may be error-prone? Limit cross-compiler compatibility? Why does the rule exist to ban local instantiations? I've been googling/searching the web for an answer to this question but have not found an explanation. Does anybody know?

Best regards,
Joakim


             reply	other threads:[~2019-01-25  9:43 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-01-25  9:43 joakimds [this message]
2019-01-25 16:36 ` Why forbid local generic instantiations? Jeffrey R. Carter
2019-01-25 21:23   ` Randy Brukardt
2019-01-26  9:56     ` Jeffrey R. Carter
2019-01-29  7:35       ` Randy Brukardt
2019-01-25 21:34 ` Randy Brukardt
2019-01-26 11:11 ` G.B.
2019-01-28 11:43   ` joakimds
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox