From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.3 required=5.0 tests=BAYES_00,INVALID_MSGID autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,55f243f32a97dc7e X-Google-Attributes: gid103376,public From: dewar@merv.cs.nyu.edu (Robert Dewar) Subject: Re: Elaboration_check For Instantiations Date: 1997/10/24 Message-ID: #1/1 X-Deja-AN: 284712454 References: <1997Oct23.202211.24396@nosc.mil> X-Complaints-To: usenet@news.nyu.edu X-Trace: news.nyu.edu 877698771 422 (None) 128.122.140.58 Organization: New York University Newsgroups: comp.lang.ada Date: 1997-10-24T00:00:00+00:00 List-Id: Charles says PACKAGE Ginspec IS GENERIC Param : IN Integer; PROCEDURE Template; PROCEDURE Instantiation IS NEW Template (1); END Ginspec; was legal in Ada 83. That is true, it is also legal in Ada 95. However in either version of the language it must raise Program_Error at runtime. Indeed GNAT will say: 1. PACKAGE Ginspec IS 2. 3. GENERIC 4. Param : IN Integer; 5. PROCEDURE Template; 6. 7. PROCEDURE Instantiation IS NEW Template (1); | >>> warning: cannot instantiate "Template" before body seen >>> warning: Program_Error will be raised at run time 8. 9. END Ginspec; Any Ada 83 compiler that executes this code without raising a Program_Error exception is seriously broken, assuming you have set the options for full runtime checking according to the RM. No Ada 83 compiler I have worked with was broken in this respect. As to why this "restriction" is here, the point is that the model of generics is that the body must be available to the compiler at the point of instantiation, or more accurately that at runtime, the body must have been elaborated. Just think about it. When you instantiate, you logically create a copy of the body, which is elaborated at the point of the instantiation. How could you create and elaborate the body of the instantiation if you have not yet elaborated the body of the generic itself. For example, consider that initializations in the body of the generic may call functions within the body of the same generic. If the body is not around, how could these calls be made?