comp.lang.ada
 help / color / mirror / Atom feed
* expression functions and raise expressions
@ 2018-03-03 18:39 Jere
  2018-03-03 20:03 ` Jeffrey R. Carter
                   ` (2 more replies)
  0 siblings, 3 replies; 7+ messages in thread
From: Jere @ 2018-03-03 18:39 UTC (permalink / raw)


I wanted to double check if I am reading the RM correctly.
From 6.8 2/4, I see that a function expression can consist entirely
of an (expression)

Section 4.4 2 says that an expression can be made up of a single
(relation)

Section 4.4 3/4 further says a relation can be a raise expression.

Given that, I expect that the following declaration/definition is correct:

      function Reference
         (Container : aliased in out Container_Type;
          Cursor    :                Cursor_Type)
          return Reference_Type
      is (raise My_Exception
          with "Reference not supported for Ordered_Sets")
      with Inline;

GNAT GPL 2017 accepts it, but FSF GNAT 7.2 for mingw64 on Win10
gives some errors:
test.ads:328:11: (Ada 2005) cannot copy object of a limited type (RM-2005 6.5(5.5/2))
test.ads:328:11: return by reference not permitted in Ada 2005

NOTE:  Reference_Type is untagged limited discriminated null
record with Implicit_Dereference defined.  Also note that a similar
function that returns an aggregate initialization compiles fine
on both versions.

I am compiling with Ada2012 mode (-gnat12 option)

I believe this to be a bug in GCC 7.2 for mingw64, but wanted to
make sure I wasn't misreading the RM.  

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

* Re: expression functions and raise expressions
  2018-03-03 18:39 expression functions and raise expressions Jere
@ 2018-03-03 20:03 ` Jeffrey R. Carter
  2018-03-03 22:53   ` Jere
  2018-03-03 20:54 ` Simon Wright
  2018-03-05 20:21 ` Randy Brukardt
  2 siblings, 1 reply; 7+ messages in thread
From: Jeffrey R. Carter @ 2018-03-03 20:03 UTC (permalink / raw)


On 03/03/2018 07:39 PM, Jere wrote:
> 
> GNAT GPL 2017 accepts it, but FSF GNAT 7.2 for mingw64 on Win10
> gives some errors:
> test.ads:328:11: (Ada 2005) cannot copy object of a limited type (RM-2005 6.5(5.5/2))
> test.ads:328:11: return by reference not permitted in Ada 2005

These messages seem to indicate -gnat05 mode.

> I am compiling with Ada2012 mode (-gnat12 option)

If that's the case, then this does look like a compiler error.

-- 
Jeff Carter
"Now look, Col. Batguano, if that really is your name."
Dr. Strangelove
31


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

* Re: expression functions and raise expressions
  2018-03-03 18:39 expression functions and raise expressions Jere
  2018-03-03 20:03 ` Jeffrey R. Carter
@ 2018-03-03 20:54 ` Simon Wright
  2018-03-03 22:54   ` Jere
  2018-03-05 20:21 ` Randy Brukardt
  2 siblings, 1 reply; 7+ messages in thread
From: Simon Wright @ 2018-03-03 20:54 UTC (permalink / raw)


Jere <jhb.chat@gmail.com> writes:

> GNAT GPL 2017 accepts it, but FSF GNAT 7.2 for mingw64 on Win10
> gives some errors:
> test.ads:328:11: (Ada 2005) cannot copy object of a limited type (RM-2005 6.5(5.5/2))
> test.ads:328:11: return by reference not permitted in Ada 2005
>
> NOTE:  Reference_Type is untagged limited discriminated null
> record with Implicit_Dereference defined.  Also note that a similar
> function that returns an aggregate initialization compiles fine
> on both versions.
>
> I am compiling with Ada2012 mode (-gnat12 option)
>
> I believe this to be a bug in GCC 7.2 for mingw64, but wanted to
> make sure I wasn't misreading the RM.  

It's fixed in GCC 8.

It fails in the same way as 7.1.0, same weird error message about 2005,
with GNAT GPL 2016.

(macOS High Sierra)


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

* Re: expression functions and raise expressions
  2018-03-03 20:03 ` Jeffrey R. Carter
@ 2018-03-03 22:53   ` Jere
  0 siblings, 0 replies; 7+ messages in thread
From: Jere @ 2018-03-03 22:53 UTC (permalink / raw)


On Saturday, March 3, 2018 at 3:03:36 PM UTC-5, Jeffrey R. Carter wrote:
> On 03/03/2018 07:39 PM, Jere wrote:
> > 
> > GNAT GPL 2017 accepts it, but FSF GNAT 7.2 for mingw64 on Win10
> > gives some errors:
> > test.ads:328:11: (Ada 2005) cannot copy object of a limited type (RM-2005 6.5(5.5/2))
> > test.ads:328:11: return by reference not permitted in Ada 2005
> 
> These messages seem to indicate -gnat05 mode.
> 
> > I am compiling with Ada2012 mode (-gnat12 option)
> 
> If that's the case, then this does look like a compiler error.
> 
I doubled checked the GPR file and it was indeed 2012, so strange error
indeed.


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

* Re: expression functions and raise expressions
  2018-03-03 20:54 ` Simon Wright
@ 2018-03-03 22:54   ` Jere
  0 siblings, 0 replies; 7+ messages in thread
From: Jere @ 2018-03-03 22:54 UTC (permalink / raw)


On Saturday, March 3, 2018 at 3:54:06 PM UTC-5, Simon Wright wrote:
> Jere writes:
> 
> > GNAT GPL 2017 accepts it, but FSF GNAT 7.2 for mingw64 on Win10
> > gives some errors:
> > test.ads:328:11: (Ada 2005) cannot copy object of a limited type (RM-2005 6.5(5.5/2))
> > test.ads:328:11: return by reference not permitted in Ada 2005
> >
> > NOTE:  Reference_Type is untagged limited discriminated null
> > record with Implicit_Dereference defined.  Also note that a similar
> > function that returns an aggregate initialization compiles fine
> > on both versions.
> >
> > I am compiling with Ada2012 mode (-gnat12 option)
> >
> > I believe this to be a bug in GCC 7.2 for mingw64, but wanted to
> > make sure I wasn't misreading the RM.  
> 
> It's fixed in GCC 8.
> 
> It fails in the same way as 7.1.0, same weird error message about 2005,
> with GNAT GPL 2016.
> 
> (macOS High Sierra)

Ok, thanks for the confirmation.  I worked around it, but it definitely
caught me offguard.


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

* Re: expression functions and raise expressions
  2018-03-03 18:39 expression functions and raise expressions Jere
  2018-03-03 20:03 ` Jeffrey R. Carter
  2018-03-03 20:54 ` Simon Wright
@ 2018-03-05 20:21 ` Randy Brukardt
  2018-03-07 22:39   ` Jere
  2 siblings, 1 reply; 7+ messages in thread
From: Randy Brukardt @ 2018-03-05 20:21 UTC (permalink / raw)


If "Reference_Type" is a limited type, then this would have been correct at 
one point: we forgot to allow raise expressions in limited contexts. (Recall 
that returning a limited expression from a function is "built-in-place" and 
only allows certain expressions, copying objects [for instance] is not 
allowed.) I noticed this when writing some ACATS tests in this area, and it 
was fixed with a recent Binding Interpretation (correction). But it won't 
formally be adopted until Ada 2020, so an Ada 2012 compiler is ""correct" if 
it allows or rejects such a use (as corrections can, but don't have to be, 
applied to the existing language).

For a non-limited type, this should be just fine. But as a raise expression 
matches any type (and thus is different than any previous Ada expression), 
it might be buggy in some odd case.

                              Randy.

"Jere" <jhb.chat@gmail.com> wrote in message 
news:60f20df9-4b33-4f29-829e-2fccb89a650a@googlegroups.com...
>I wanted to double check if I am reading the RM correctly.
> From 6.8 2/4, I see that a function expression can consist entirely
> of an (expression)
>
> Section 4.4 2 says that an expression can be made up of a single
> (relation)
>
> Section 4.4 3/4 further says a relation can be a raise expression.
>
> Given that, I expect that the following declaration/definition is correct:
>
>      function Reference
>         (Container : aliased in out Container_Type;
>          Cursor    :                Cursor_Type)
>          return Reference_Type
>      is (raise My_Exception
>          with "Reference not supported for Ordered_Sets")
>      with Inline;
>
> GNAT GPL 2017 accepts it, but FSF GNAT 7.2 for mingw64 on Win10
> gives some errors:
> test.ads:328:11: (Ada 2005) cannot copy object of a limited type (RM-2005 
> 6.5(5.5/2))
> test.ads:328:11: return by reference not permitted in Ada 2005
>
> NOTE:  Reference_Type is untagged limited discriminated null
> record with Implicit_Dereference defined.  Also note that a similar
> function that returns an aggregate initialization compiles fine
> on both versions.
>
> I am compiling with Ada2012 mode (-gnat12 option)
>
> I believe this to be a bug in GCC 7.2 for mingw64, but wanted to
> make sure I wasn't misreading the RM. 


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

* Re: expression functions and raise expressions
  2018-03-05 20:21 ` Randy Brukardt
@ 2018-03-07 22:39   ` Jere
  0 siblings, 0 replies; 7+ messages in thread
From: Jere @ 2018-03-07 22:39 UTC (permalink / raw)


On Monday, March 5, 2018 at 3:21:18 PM UTC-5, Randy Brukardt wrote:
> "Jere" wrote in message 
> >I wanted to double check if I am reading the RM correctly.
> > From 6.8 2/4, I see that a function expression can consist entirely
> > of an (expression)
> >
> > Section 4.4 2 says that an expression can be made up of a single
> > (relation)
> >
> > Section 4.4 3/4 further says a relation can be a raise expression.
> >
> > Given that, I expect that the following declaration/definition is correct:
> >
> >      function Reference
> >         (Container : aliased in out Container_Type;
> >          Cursor    :                Cursor_Type)
> >          return Reference_Type
> >      is (raise My_Exception
> >          with "Reference not supported for Ordered_Sets")
> >      with Inline;
> >
> > GNAT GPL 2017 accepts it, but FSF GNAT 7.2 for mingw64 on Win10
> > gives some errors:
> > test.ads:328:11: (Ada 2005) cannot copy object of a limited type (RM-2005 
> > 6.5(5.5/2))
> > test.ads:328:11: return by reference not permitted in Ada 2005
> >
> > NOTE:  Reference_Type is untagged limited discriminated null
> > record with Implicit_Dereference defined.  Also note that a similar
> > function that returns an aggregate initialization compiles fine
> > on both versions.
> >
> > I am compiling with Ada2012 mode (-gnat12 option)
> >
> > I believe this to be a bug in GCC 7.2 for mingw64, but wanted to
> > make sure I wasn't misreading the RM.
> If "Reference_Type" is a limited type, then this would have been correct at 
> one point: we forgot to allow raise expressions in limited contexts. (Recall 
> that returning a limited expression from a function is "built-in-place" and 
> only allows certain expressions, copying objects [for instance] is not 
> allowed.) I noticed this when writing some ACATS tests in this area, and it 
> was fixed with a recent Binding Interpretation (correction). But it won't 
> formally be adopted until Ada 2020, so an Ada 2012 compiler is ""correct" if 
> it allows or rejects such a use (as corrections can, but don't have to be, 
> applied to the existing language).
> 
> For a non-limited type, this should be just fine. But as a raise expression 
> matches any type (and thus is different than any previous Ada expression), 
> it might be buggy in some odd case.
> 
>                               Randy.
> 
Thanks!

It was a limited type.  I guess for now, I won't use them in expression
functions then so I can keep it portable.  It was just convenient, but
not a show stopper.


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

end of thread, other threads:[~2018-03-07 22:39 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-03-03 18:39 expression functions and raise expressions Jere
2018-03-03 20:03 ` Jeffrey R. Carter
2018-03-03 22:53   ` Jere
2018-03-03 20:54 ` Simon Wright
2018-03-03 22:54   ` Jere
2018-03-05 20:21 ` Randy Brukardt
2018-03-07 22:39   ` Jere

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