This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Clarifying attribute-const


> On Oct 1, 2015, at 11:34 AM, Alexander Monakov <amonakov@ispras.ru> wrote:
> 
> Can you expand on the "etc." a bit, i.e., may the compiler ...
> 
>  - move a call to a "const" function above a conditional branch, 
>    causing a conditional throw to happen unconditionally?
No, calls may only be omitted, not moved.
> 
>  - move a call to a "const" function below a conditional branch, 
>    causing an unconditional throw to happen only conditionally?
> No, calls may only be omitted, not moved.
> 
>  - reorder calls to "const" functions  w.r.t. code with side effects, or
>    other throwing functions?
A call to a pure function (Ada's version of "const") may be omitted if its result is not used,
or if results of an earlier call with the same argument values (including referenced values) can
be used. This is allowed regardless of whether the original function had any side effects.
Note that if a function raised an exception (threw) the call can only be replaced with throwing
that exception.

So, reordering is not allowed, but omitting is, in the context of Ada.

  -Geert


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]