From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on ip-172-31-65-14.ec2.internal X-Spam-Level: X-Spam-Status: No, score=-1.9 required=3.0 tests=BAYES_00,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 Path: eternal-september.org!reader01.eternal-september.org!aioe.org!Yr2L9qaRshuL+yFKTxsDBA.user.46.165.242.75.POSTED!not-for-mail From: Simon Wright Newsgroups: comp.lang.ada Subject: Re: Compiler error (2) ? Date: Mon, 26 Sep 2022 09:12:05 +0100 Organization: Aioe.org NNTP Server Message-ID: References: <7085edb5-688c-410c-b401-23ff3ca2a38fn@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain Injection-Info: gioia.aioe.org; logging-data="62277"; posting-host="Yr2L9qaRshuL+yFKTxsDBA.user.gioia.aioe.org"; mail-complaints-to="abuse@aioe.org"; User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/28.1 (darwin) Cancel-Lock: sha1:J+5Q9HsgC3mV9maFQ4NSEZkFfQk= X-Notice: Filtered by postfilter v. 0.9.2 Xref: reader01.eternal-september.org comp.lang.ada:64413 List-Id: I'm not sure what compiler error you mean. Agreed that the code as stands reports a strange issue, 11. S_Names: constant S_Names_P.Vector := [for I in 3..N => S0]; | >>> error: expected type "Standard.Integer" >>> error: found type "Ada.Containers.Count_Type" which does look like a compiler error (even if it's only misreporting a valid issue, I'm not sure). What's more interesting is what happens if you make your suggested change and it compiles. When you run it, $ ./reinert_2 raised CONSTRAINT_ERROR : test1a.s_names_p.Replace_Element: Index is out of range Running this under the debugger, with 'catch exception', Catchpoint 1, CONSTRAINT_ERROR (test1a.s_names_p.Replace_Element: Index is out of range) at 0x0000000100008ae5 in test1a () at reinert_2.adb:15 15 s_names: constant s_names_p.Vector := [for i in 3..n => S0]; So, what's Index? (gdb) p index No definition of "index" in current context. Looing at the backtrace, (gdb) bt [...] #4 0x0000000100011711 in test1a.s_names_p.replace_element (container=..., index=6, new_item=s0) at /opt/gcc-12.1.0/lib/gcc/x86_64-apple-darwin15/12.1.0/adainclude/a-convec.adb:2522 #5 0x0000000100008ae5 in test1a () at reinert_2.adb:15 Frame 4 is in the runtime; maybe we can see what's going on, (gdb) fr 4 #4 0x0000000100011711 in test1a.s_names_p.replace_element (container=..., index=6, new_item=s0) at /opt/gcc-12.1.0/lib/gcc/x86_64-apple-darwin15/12.1.0/adainclude/a-convec.adb:2522 2522 raise Constraint_Error with "Index is out of range"; (gdb) p index $1 = 6 Hmm. What does the source say? (gdb) l 2517 is 2518 begin 2519 TE_Check (Container.TC); 2520 2521 if Checks and then Index > Container.Last then 2522 raise Constraint_Error with "Index is out of range"; 2523 end if; 2524 2525 Container.Elements.EA (Index) := New_Item; 2526 end Replace_Element; So Index (6) is more than Container.Last: (gdb) p container $2 = (elements => 0x600000008000, last => 5, tc => (busy => 0, lock => 0)) (gdb) 6 is certainly more than 5. Where does 5 come from? Index is Positive. We were hoping to have our container with indices supporting values up to 7, but the first index of a container has to be Index_Type'First i.e. 1; the compiler has looked at the length of the aggregate (5) and created an empty Vector s_names of that length. Clearly you can't do slices in this context!