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


> First, a belated follow-up to https://gcc.gnu.org/PR66512 . The bug is
> asking why attribute-const appears to have a weaker effect in C++, compared
> to C. The answer in that bug is that GCC assumes that attribute-const
> function can terminate by throwing an exception.

FWIW there is an equivalent semantics in Ada: the "const" functions can throw 
and the language explicitly allows them to be CSEd in this case, etc.

> That doesn't actually seem reasonable.  Consider that C counterpart to
> throwing is longjmp; it seems to me that GCC should behave consistently:
> either assume that attribute-const may both longjmp and throw (I guess
> nobody wants that), or that it may not longjmp nor throw.  Intuitively, if
> "const" means "free of side effects so that calls can be moved
> speculatively or duplicated", then non-local control flow transfer via
> throwing should be disallowed as well.

This would pessimize a lot languages where exceptions are pervasive.

> In any case, it would be nice the intended compiler behavior could be
> explicitely stated in the manual.

Agreed.

-- 
Eric Botcazou


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