Daniel Marjamäki <daniel.marjam...@gmail.com> writes: > Do you have any opinion about adding a warning for: > > int f(char c) > { > return 10 * (c == 13) ? 1 : 2; > } > > The multiplication has no effect. The function returns either 1 or 2. > > It would be interesting to know how a MELT script could look like for > such a case.
The problem with warnings for this kind of code in C/C++ is that it often arises in macro expansions. I think it would be necessary to first develop a scheme which lets us determine whether code resulted from a macro expansion or not, which I think would be quite useful in a number of different cases. > As far as I see the multiplication doesn't exist in the gimple format > (looking at a.c.004t.gimple generated by -fdump-tree-all). It gets constant folded in the front end. Ian