comp.lang.ada
 help / color / mirror / Atom feed
From: Adam Beneschan <adam@irvine.com>
Subject: Re: Gnat 2013 is out!
Date: Wed, 29 May 2013 19:01:50 -0700 (PDT)
Date: 2013-05-29T19:01:50-07:00	[thread overview]
Message-ID: <32d94173-533a-471e-95a0-abb73a6cdcc2@googlegroups.com> (raw)
In-Reply-To: <ko603g$dde$1@loke.gir.dk>

On Wednesday, May 29, 2013 3:39:44 PM UTC-7, Randy Brukardt wrote:

> >> But it's reporting a problem with my Ada 2005 Math Extensions .. not
> >> so good (for me).
> 
> > Turned out to be a warning new to GNAT GPL 2013 (also in GCC 4.8.0):  
> > had a subprogram with two out parameters that designated the same
> > object. It was a dummy, though, so no harm done.
>
> >   ada_numerics-generic_arrays.adb:325:28: warning: writable actual for
> >   "V_L" overlaps with actual for "V_R"
> 
> You do know that's illegal in some cases in Ada 2012? (A known and intended 
> incompatibility.) I wouldn't be surprised if GNAT is putting out a warning 
> in other modes in order to reduce the incompatibility. (Or, perhaps, they're 
> using the code they had to write to make the Ada 2012 check to issue 
> warnings in other cases.) I'd suggest getting rid of any such code.

Even before Ada 2012, it's been possible to run into a problem with "distinct access paths".  A subprogram with two OUT parameters could set a component in one OUT parameter, and then later try reading it back; if it's written something into the other OUT parameter in between, and if the caller uses the same actual for both OUT parameters, it could cause a real problem.  I'm guessing that Simon is calling one of his own routines, so he knows that won't happen.  But it still seems like bad practice.

I've always wanted some kind of feature in Ada that would allow a caller to provide a "dummy" for OUT parameters, without having to declare a new variable.  The compiler would allocate a temporary object (and a separate one for each use of a "dummy") and then discard it after the call.  It wouldn't work well when parameter types are unconstrained array or discriminant records, though.  

Now that we have preconditions, and Has_Same_Storage and Overlap_Storage attributes [this is why I was looking into those! :-)], in theory it should be possible for programmers to use this any time there are two not-by-copy parameters (not both IN parameters) that shouldn't overlap.  Then it would be safe to use the same dummy variable for both (or other overlapping cases) if there's no such precondition.  The programmer has promised that the body of the subprogram is able to handle overlap.  But that doesn't seem feasible to me, since I think in *most* cases, the intent of subprograms with OUT or IN OUT parameters is that they're not expected to overlap.  Expecting a precondition to be added to all such subprograms seems like too big a burden.

I think the best practice here is: don't ever call a subprogram with overlapping parameters (if they're not both IN parameters), unless there is some comment on the subprogram declaration saying that it's OK.  (Or an implementation-defined pragma.)

                             -- Adam



  reply	other threads:[~2013-05-30  2:01 UTC|newest]

Thread overview: 55+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-05-29 13:36 Gnat 2013 is out! J-P. Rosen
2013-05-29 15:03 ` Simon Wright
2013-05-29 16:13   ` Simon Wright
2013-05-29 22:39     ` Randy Brukardt
2013-05-30  2:01       ` Adam Beneschan [this message]
2013-05-30  8:01         ` Bill Findlay
2013-05-30 23:09           ` Dennis Lee Bieber
2013-05-31  5:02             ` J-P. Rosen
2013-05-31 18:35             ` Bill Findlay
2013-05-30 10:39         ` Simon Wright
2013-05-30 16:21           ` Adam Beneschan
2013-05-30 19:53         ` Randy Brukardt
2013-05-31  7:41           ` Dmitry A. Kazakov
2013-05-31 11:30           ` Stefan.Lucks
2013-05-31 12:03             ` Niklas Holsti
2013-05-31 22:07             ` Randy Brukardt
2013-06-01 11:51               ` Georg Bauhaus
2013-06-03 14:52                 ` Adam Beneschan
2013-06-04 17:42                   ` Wesley Pan
2013-06-04 18:34                     ` Adam Beneschan
2013-06-04 19:00                       ` Wesley Pan
2013-06-05 15:40                     ` Eryndlia Mavourneen
2013-06-11  2:39                   ` Randy Brukardt
2013-06-11  6:31                     ` Georg Bauhaus
2013-06-19 21:57                       ` Randy Brukardt
2013-05-30  0:31 ` Dennis Lee Bieber
2013-05-31 16:12 ` dptrash
2013-06-01  5:10   ` Stephen Leake
2013-06-01  6:00   ` Per Sandberg
2013-06-01  6:46   ` J-P. Rosen
2013-06-01 15:22     ` Bill Findlay
2013-08-27 14:08   ` Yannick Duchêne (Hibou57)
2013-08-27 20:05     ` wilson
2013-08-27 22:59       ` Dennis Lee Bieber
2013-08-28  7:35         ` Dmitry A. Kazakov
2013-08-28 23:39           ` Dennis Lee Bieber
2013-06-07  2:41 ` gautier_niouzes
2013-06-07 15:52 ` mjsilva
2013-06-07 20:15   ` Dmitry A. Kazakov
2013-06-09 18:51     ` MatthiasR
2013-06-08  6:22   ` Simon Wright
2013-06-08 23:23     ` mjsilva
2013-06-10 11:07   ` Rego, P.
2013-06-13 13:30     ` Rego, P.
2013-06-17  6:35       ` Jacob Sparre Andersen
2013-06-22  8:17         ` MatthiasR
2014-03-18  0:04           ` Rego, P.
2013-06-11  7:52 ` Maciej Sobczak
2013-06-11  9:35   ` J-P. Rosen
2013-06-11 12:09   ` John Doe
2013-06-12  7:58 ` Maciej Sobczak
2013-06-12 11:01   ` G.B.
2013-06-12 20:01   ` Robert A Duff
2013-06-12 20:36     ` Georg Bauhaus
2013-06-13  7:38     ` Maciej Sobczak
replies disabled

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