comp.lang.ada
 help / color / mirror / Atom feed
* Misleading Compiler Warning
@ 2003-02-02 14:58 Volkert
  2003-02-02 19:03 ` Jeffrey Carter
  2003-02-03  6:45 ` Simon Wright
  0 siblings, 2 replies; 7+ messages in thread
From: Volkert @ 2003-02-02 14:58 UTC (permalink / raw)


The snippet is reproduced from a large application we currenty
bringing from DEC Ada 83 to GNAT (OpenVMS).... the GNAT 3.16w 
gives a Compiler-Warning whereas the DEC Compiler keeps silent. 

% gnat make wmain.adc
gcc -c -x ada wmain.adc
gcc -c -x ada pack.adc
pack.adc:9:03: warning: in instantiation at Gen.adc:4
pack.adc:9:03: warning: value not in range of type "Standard.Integer"
pack.adc:9:03: warning: "Constraint_Error" will be raised at run time
gnatbind -x wmain.ali
gnatlink wmain.ali

The example runs on both compilers without raising a Constraint_Error.

Is it just a misleading warning message ... if so, i send a bug-report to act.

Volkert

PS: ObjectAda 7.2.1 compiles also with no warnings

----

with Pack;

procedure WMain is

  type T is range 0 .. 100;

  package P is new Pack(T=>T);

begin
 
  P.Do_It;

end;

----

generic
  type T is range <>;
package Pack is

  procedure Do_It;

end Pack;

----
with Gen;

package body Pack is

  package My_Gen is 
    new Gen(s => Float);

  package Inner_Gen_My_Gen is 
    new My_Gen.Inner_Gen(T => T);

  procedure Do_It is
  begin
     Inner_Gen_My_Gen.Do_It;
  end;

end Pack;

---

generic
   type S is private;
package Gen is

   generic
      type T is range <>;
   package Inner_Gen is
      procedure Do_It;
   end Inner_Gen;

end Gen;

---

package body Gen is
   
   package body Inner_Gen is
      type B is array(T) of Boolean;
      pragma Pack(B);
      type C is array (0 .. 100) of B;

      procedure Do_It is
        O : C;
      begin
        O(1)(0) := False;
      end;
   
   end;

end Gen;

----
gnat.adc

pragma Source_File_Name (
  Spec_File_Name  => "*_.adc",
  Casing          => MixedCase,
  Dot_Replacement => "__");

pragma Source_File_Name (
  Body_File_Name  => "*.adc",
  Casing          => MixedCase,
  Dot_Replacement => "__");



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

* Re: Misleading Compiler Warning
  2003-02-02 14:58 Misleading Compiler Warning Volkert
@ 2003-02-02 19:03 ` Jeffrey Carter
  2003-02-03  6:04   ` Volkert
  2003-02-03  6:45 ` Simon Wright
  1 sibling, 1 reply; 7+ messages in thread
From: Jeffrey Carter @ 2003-02-02 19:03 UTC (permalink / raw)


Volkert wrote:
> pack.adc:9:03: warning: in instantiation at Gen.adc:4
> pack.adc:9:03: warning: value not in range of type "Standard.Integer"
> pack.adc:9:03: warning: "Constraint_Error" will be raised at run time

This is an unusual warning. However, I think some warning is a good 
idea; see below.

> 
> generic
>    type S is private;
> package Gen is
> 
>    generic
>       type T is range <>;
>    package Inner_Gen is
>       procedure Do_It;
>    end Inner_Gen;
> 
> end Gen;
> 
> ---
> 
> package body Gen is
>    
>    package body Inner_Gen is
>       type B is array(T) of Boolean;
>       pragma Pack(B);
>       type C is array (0 .. 100) of B;
> 
>       procedure Do_It is
>         O : C;
>       begin
>         O(1)(0) := False;

                ^ Here you assume that 0 is a value of the formal type T

>       end;
>    
>    end;
> 
> end Gen;

There is no guarantee that zero is a value of the actual type used for 
the formal type T; a (sub)type with a 'First of one is very likely. 
While the warning you got is not very good, some sort of warning seems 
in order here.

-- 
Jeff Carter
"I've got to stay here, but there's no reason
why you folks shouldn't go out into the lobby
until this thing blows over."
Horse Feathers




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

* Re: Misleading Compiler Warning
  2003-02-02 19:03 ` Jeffrey Carter
@ 2003-02-03  6:04   ` Volkert
  2003-02-03 16:54     ` Jeffrey Carter
  0 siblings, 1 reply; 7+ messages in thread
From: Volkert @ 2003-02-03  6:04 UTC (permalink / raw)


> >    
> >    package body Inner_Gen is
> >       type B is array(T) of Boolean;
> >       pragma Pack(B);
> >       type C is array (0 .. 100) of B;
> > 
> >       procedure Do_It is
> >         O : C;
> >       begin
> >         O(1)(0) := False;
> 
>                 ^ Here you assume that 0 is a value of the formal type T
> 
> >       end;
> >    
> >    end;
> > 
> > end Gen;
> 
> There is no guarantee that zero is a value of the actual type used for 
> the formal type T; a (sub)type with a 'First of one is very likely. 
> While the warning you got is not very good, some sort of warning seems 
> in order here.

This line was only for testing. Remove it and you will get the same gnat warning.


With regards
Volkert



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

* Re: Misleading Compiler Warning
  2003-02-02 14:58 Misleading Compiler Warning Volkert
  2003-02-02 19:03 ` Jeffrey Carter
@ 2003-02-03  6:45 ` Simon Wright
  2003-02-09  3:14   ` Robert I. Eachus
  1 sibling, 1 reply; 7+ messages in thread
From: Simon Wright @ 2003-02-03  6:45 UTC (permalink / raw)


volkert@nivoba.de (Volkert) writes:

> The snippet is reproduced from a large application we currenty
> bringing from DEC Ada 83 to GNAT (OpenVMS).... the GNAT 3.16w 
> gives a Compiler-Warning whereas the DEC Compiler keeps silent. 
> 
> % gnat make wmain.adc
> gcc -c -x ada wmain.adc
> gcc -c -x ada pack.adc
> pack.adc:9:03: warning: in instantiation at Gen.adc:4
> pack.adc:9:03: warning: value not in range of type "Standard.Integer"
> pack.adc:9:03: warning: "Constraint_Error" will be raised at run time
> gnatbind -x wmain.ali
> gnatlink wmain.ali
> 
> The example runs on both compilers without raising a Constraint_Error.
> 
> Is it just a misleading warning message ... if so, i send a
> bug-report to act.

I'm sure this is a bad warning -- if only because there is nothing in
the regenerated code (-gnatdg) about constraint errors.

It also happens on Saturday's experimental GCC-3.4.

If you have 3.16w, you should be supported -- ACT are very quick to
respond to reports like this, IME, don't hold back!



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

* Re: Misleading Compiler Warning
  2003-02-03  6:04   ` Volkert
@ 2003-02-03 16:54     ` Jeffrey Carter
  0 siblings, 0 replies; 7+ messages in thread
From: Jeffrey Carter @ 2003-02-03 16:54 UTC (permalink / raw)


Volkert wrote:
> 
> This line was only for testing. Remove it and you will get the same gnat warning.

Then I suggest you report it.

-- 
Jeff Carter
"We use a large, vibrating egg."
Annie Hall




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

* Re: Misleading Compiler Warning
  2003-02-03  6:45 ` Simon Wright
@ 2003-02-09  3:14   ` Robert I. Eachus
  2003-02-09 15:31     ` Volkert
  0 siblings, 1 reply; 7+ messages in thread
From: Robert I. Eachus @ 2003-02-09  3:14 UTC (permalink / raw)


Simon Wright wrote:
>% gnat make wmain.adc
>gcc -c -x ada wmain.adc
>gcc -c -x ada pack.adc
>pack.adc:9:03: warning: in instantiation at Gen.adc:4
>pack.adc:9:03: warning: value not in range of type "Standard.Integer"
>pack.adc:9:03: warning: "Constraint_Error" will be raised at run time
>gnatbind -x wmain.ali
>gnatlink wmain.ali
>
>The example runs on both compilers without raising a Constraint_Error.
>
>Is it just a misleading warning message ... if so, i send a
>bug-report to act.

Definitely not a bug, or the bug is not where you expect.  You are 
apparently compiling with integer range checking off.  So the warning is 
right, but of course, Constraint_Error will not be raised with these 
compiler options.

Try recompiling with -gnato
Enable numeric overflow checking (which is not normally enabled by default).





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

* Re: Misleading Compiler Warning
  2003-02-09  3:14   ` Robert I. Eachus
@ 2003-02-09 15:31     ` Volkert
  0 siblings, 0 replies; 7+ messages in thread
From: Volkert @ 2003-02-09 15:31 UTC (permalink / raw)


> Definitely not a bug, or the bug is not where you expect.  You are 
> apparently compiling with integer range checking off.  So the warning is 
> right, but of course, Constraint_Error will not be raised with these 
> compiler options.
> 
> Try recompiling with -gnato
> Enable numeric overflow checking (which is not normally enabled by default).
We have send a bug report to ACT and they have confirmed 
that it is a bug.

Volkert



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

end of thread, other threads:[~2003-02-09 15:31 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-02-02 14:58 Misleading Compiler Warning Volkert
2003-02-02 19:03 ` Jeffrey Carter
2003-02-03  6:04   ` Volkert
2003-02-03 16:54     ` Jeffrey Carter
2003-02-03  6:45 ` Simon Wright
2003-02-09  3:14   ` Robert I. Eachus
2003-02-09 15:31     ` Volkert

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