(Debian bug #279893) -- legal instantiation rejected; illegal instantiation accepted -- adapted from John Woodruff c.l.a. post
generic type T1 is private; package pak1 is subtype T3 is T1; end pak1; with pak1; generic type T2 is private; package pak2 is package the_pak1 is new pak1 (T1 => T2); end pak2; generic type T2 is access the_pak1.T3; package pak2.pak3 is end pak2.pak3; with pak1; with pak2.pak3; package Test_129 is type T4 is null record; type T5 is null record; subtype T3 is T5; -- line 9: triggers the bug at line 16 type T4_ptr is access T4; type T5_ptr is access T5; package new_pak2 is new pak2 (T2 => T4); package new_pak3a is new new_pak2.pak3(T2 => T4_ptr); -- line 15: Legal package new_pak3b is new new_pak2.pak3(T2 => T5_ptr); -- line 16: Illegal end Test_129; The instantiation at line 15 is legal because T4_ptr is an access to T4, and the previous instantiations make it so that T4 = new_pak2.T2 = new_pak2.the_pak1.T1 = pak2.the_pak1.T3. In contrast, line 16 is illegal because T5 /= new_pak2.T2. Thus, the expected output from gnat is: test_129.ads:16:49: designated type of actual does not match that of formal "T2" test_129.ads:16:49: instantiation abandoned gnatmake: "test_129.ads" compilation error The actual output from gnat is: test_129.ads:15:49: designated type of actual does not match that of formal "T2" test_129.ads:15:49: instantiation abandoned gnatmake: "test_129.ads" compilation error The subtype at line 9 happens to be a homograph of pak1.T3. Removing this line, or renaming Test_129.T3, causes the actual output to become: test_129.ads:15:49: designated type of actual does not match that of formal "T2" test_129.ads:15:49: instantiation abandoned test_129.ads:16:49: designated type of actual does not match that of formal "T2" test_129.ads:16:49: instantiation abandoned gnatmake: "test_129.ads" compilation error -- Summary: Legal instantiation rejected; illegal instantiation accepted Product: gcc Version: 3.4.2 Status: UNCONFIRMED Severity: normal Priority: P2 Component: ada AssignedTo: unassigned at gcc dot gnu dot org ReportedBy: ludovic dot brenta at insalien dot org CC: gcc-bugs at gcc dot gnu dot org http://gcc.gnu.org/bugzilla/show_bug.cgi?id=18453