Semantics of ^^, Version 3 (Final?)
Lars T. Kyllingstad
public at kyllingen.NOSPAMnet
Wed Dec 9 01:59:19 PST 2009
Rainer Deyke wrote:
> Lars T. Kyllingstad wrote:
>> Rainer Deyke wrote:
>>> I don't care if x^^y with y < 0 is 0, a runtime error, or even undefined
>>> behavior. However, having different behavior if x is a compile-time
>>> constant than if x is a variable is unacceptable because it silently
>>> changes the (defined) behavior of a function when a runtime parameter is
>>> changed to a template parameter or vice versa, or even when the compiler
>>> becomes a bit more clever about CTFE.
>> I don't think it's a problem: Either it works as expected, or it causes
>> a compile-time error.
>
> Not quite. Under the proposal, -1^^-1 works (i.e. produces the correct
> result) at compile time but fails at runtime.
That depends on which of these two rules gets the higher precedence:
Don wrote:
> * If x is the compile-time constant -1 and y is an integer, x^^y is rewritten as (y & 1) ? -1 : 1.
> * If y < 0, an integer divide error occurs, regardless of the value of x.
I suppose it should be the latter.
-Lars
More information about the Digitalmars-d
mailing list