comp.lang.ada
 help / color / mirror / Atom feed
* Possible bug?
@ 2015-07-10  9:46 Anatoly Chernyshev
  2015-07-10 10:06 ` J-P. Rosen
  0 siblings, 1 reply; 4+ messages in thread
From: Anatoly Chernyshev @ 2015-07-10  9:46 UTC (permalink / raw)


Hello everyone,

Here is a tiny program compiled in GNAT 2015, under Win 7:

procedure fail_arr is
n_d,n_f: constant integer:=10;
type tss is array (1..n_d,1..n_f) of float;
tser:tss:=(others=>(0.0,0.0));
begin
for i in tser'range(1) loop
for j in tser'range(2) loop
tser(i,j):=0.0;
end loop;
end loop;
end fail_arr;

From my understanding, in the declaration of tser, its first two columns must be populated with 0.0, and the rest is to be left uninitialized. But under no circumstances shall the array to have dimensions (n_d, 2). But that's exactly what happens in the program.

The compiler even gives me nice soft warning about this:

4:11 warning: too few elements for type "tss" defined at line 3
4:11 warning: "Constraint_Error" will be raised at run time

Even though it should abort the compilation with an error message. No?

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Possible bug?
  2015-07-10  9:46 Possible bug? Anatoly Chernyshev
@ 2015-07-10 10:06 ` J-P. Rosen
  2015-07-10 22:33   ` Randy Brukardt
  0 siblings, 1 reply; 4+ messages in thread
From: J-P. Rosen @ 2015-07-10 10:06 UTC (permalink / raw)


Le 10/07/2015 11:46, Anatoly Chernyshev a écrit :

> procedure fail_arr is
> n_d,n_f: constant integer:=10;
> type tss is array (1..n_d,1..n_f) of float;
> tser:tss:=(others=>(0.0,0.0));
> begin
> for i in tser'range(1) loop
> for j in tser'range(2) loop
> tser(i,j):=0.0;
> end loop;
> end loop;
> end fail_arr;
> 
> From my understanding, in the declaration of tser, its first two
> columns must be populated with 0.0, and the rest is to be left
> uninitialized.
If that's what you want, you have to say so:
> tser:tss:=(others=>(0.0,0.0, others => <>));

> But under no circumstances shall the array to have
> dimensions (n_d, 2). But that's exactly what happens in the program.
> 
> The compiler even gives me nice soft warning about this:
> 
> 4:11 warning: too few elements for type "tss" defined at line 3 4:11
> warning: "Constraint_Error" will be raised at run time
> 
> Even though it should abort the compilation with an error message.
> No?
> 
No. What happens is that it constructs an initialization aggregate whose
bounds are (n_d, 2), and then raises Constraint_Error because the bounds
of the initial value do not match those of the variable. That's exactly
what the warning is telling you.


-- 
J-P. Rosen
Adalog
2 rue du Docteur Lombard, 92441 Issy-les-Moulineaux CEDEX
Tel: +33 1 45 29 21 52, Fax: +33 1 45 29 25 00
http://www.adalog.fr

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Possible bug?
  2015-07-10 10:06 ` J-P. Rosen
@ 2015-07-10 22:33   ` Randy Brukardt
  2015-07-11  0:29     ` Anatoly Chernyshev
  0 siblings, 1 reply; 4+ messages in thread
From: Randy Brukardt @ 2015-07-10 22:33 UTC (permalink / raw)


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain, Size: 1409 bytes --]

"J-P. Rosen" <rosen@adalog.fr> wrote in message 
news:mno5d2$s8e$1@dont-email.me...
> Le 10/07/2015 11:46, Anatoly Chernyshev a écrit :
...
>> Even though it should abort the compilation with an error message.
>> No?
>>
> No. What happens is that it constructs an initialization aggregate whose
> bounds are (n_d, 2), and then raises Constraint_Error because the bounds
> of the initial value do not match those of the variable. That's exactly
> what the warning is telling you.

Right. More generally, "out of range" errors are always reported at runtime; 
compilers often give a warning but they're not allowed to reject the 
program. That's because perfectly sensible programs might contain an "out of 
range" error in code that will never be executed, and one would be very 
annoyed if the program was rejected.

Consider:

  procedure Something (Mem : in Integer) is
     Size : constant := 0;
  begin
     if Size /= 0 then
         ... Mem / Size ...
     else
         ...
     end if;
  end Something;

If dividing by zero was a compile-time error, it wouldn't be possible to 
divide by a constant whose value might be zero, even in code that's 
protected by a pre-test. (Imagine that Size started out as 1 and then later 
got changed to 0 during program maintenance.) That would be very annoying.

The same is true for aggregates, since they can be sized by constants.

                     Randy.


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Possible bug?
  2015-07-10 22:33   ` Randy Brukardt
@ 2015-07-11  0:29     ` Anatoly Chernyshev
  0 siblings, 0 replies; 4+ messages in thread
From: Anatoly Chernyshev @ 2015-07-11  0:29 UTC (permalink / raw)


Right. I guess, I became overrelaxed at Ada's capacity to straighten up whatever stupid things I could put in the code.

> > No. What happens is that it constructs an initialization aggregate whose
> > bounds are (n_d, 2), and then raises Constraint_Error because the bounds
> > of the initial value do not match those of the variable. That's exactly
> > what the warning is telling you.
> 
> Right. More generally, "out of range" errors are always reported at runtime; 
> compilers often give a warning but they're not allowed to reject the 
> program. That's because perfectly sensible programs might contain an "out of 
> range" error in code that will never be executed, and one would be very 
> annoyed if the program was rejected.


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2015-07-11  0:29 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-07-10  9:46 Possible bug? Anatoly Chernyshev
2015-07-10 10:06 ` J-P. Rosen
2015-07-10 22:33   ` Randy Brukardt
2015-07-11  0:29     ` Anatoly Chernyshev

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