On Sat, Aug 06, 2011 at 06:45:36PM +0200, Mikael Morin wrote: > On Saturday 06 August 2011 18:06:58 Janus Weil wrote: > > >> It is wrong to assume that expressions are unequal because we cannot > > >> prove they are equal, with all the limitations that we currently > > >> have. This will introduce rejects-valid bugs. > > > > > > In the PR at > > > http://gcc.gnu.org/bugzilla/show_bug.cgi?id=49638#c8 > > > I quote the standard: > > > > > > 4.5.7.3 (type-bound procedure overriding) has: > > > ? Either both shall be subroutines or both shall be functions having the > > > same result characteristics (12.3.3). > > > > > > 12.3.3 (Characteristics of function results): > > > If a type parameter of a function result or a bound of a function result > > > array is not a constant expression, the > > > exact dependence on the entities in the expression is a characteristic > > > > > > > > > So the standards is more restrictive than expression values being the > > > same. It requires _the exact same dependence on the entities_. My > > > reading of this is that 3*(x+1) vs 3*x+3 is right to be rejected, same > > > for (a+b)+c vs a+(b+c). The only worrying case that I see is the one you > > > pointed out: a+b+c vs c+b+a (without brackets). > > > > Huh, I don't see what is so different between > > > > 1) 3*(x+1) vs 3*x+3 and > > 2) a+b+c vs c+b+a > > > > In both cases the expressions look different at first sight, but can > > be transformed into each other mathematically. So I'd say they are > > mathematically equivalent, although the spelled-out representations of > > these expressions differ. > I was looking at the standard, because I was not so sure myself. > Here is what is written (7.1.5.2.4): > > Once the interpretation of a numeric intrinsic operation is established, the > processor may evaluate any mathematically equivalent expression, provided > that > the integrity of parentheses is not violated. > > Two expressions of a numeric type are mathematically equivalent if, for all > possible values of their primaries, theirmathematical values are equal. > > > So parentheses have to be respected; other than that anything is possible.
See Note 7.18. X*(Y-Z) -> X*Y - X*Z is a forbidden transformation (there is no noted restriction on Z > 0). a + b + c -> b + a + c -> b + (a + c) is a sequence of allowable transformations. -- Steve