
Kyle Lutz wrote
On Tue, Sep 2, 2014 at 10:19 PM, Robert Ramey <
ramey@
> wrote:
It's been pointed out that the unused branch needs to be compiled even if the result is to be thrown away so that the program won't contain invalid code which will only create a surprise when another type for T is used. Actually, I'm quite sympathetic to this argument. Generic code shouldn't resolve to invalid code for some types. That mean that it's not really generic.
Despite your expectations, this is not how optimizers work (or are allowed to work). Would you expect the following to compile?
int main() { if(1 == 2){ !@#$%^&*(); } return 0; }
No - I think that's what I said above. Your example here doesn't depend upon any template parameter so I don't think it has a lot do with the discussion. In practice the compile will trap with an error and the programmer will eliminate the offending code and that will be the end of it. If the compiler just through it away, that would be the end of it as well. No real difference. Except that in this case its very clear that the programmer has some sort of intention which he hasn't been able to express - so compiling the obviously incorrect code will tell he hasn't thought enough about what he wants or he made a typographical mistake. So far I haven't seen anyone propose an example which benefits from the original proposal. Seems to me a solution to a non-existent problem. Robert Ramey -- View this message in context: http://boost.2283326.n4.nabble.com/static-if-Is-there-interest-in-a-static-i... Sent from the Boost - Dev mailing list archive at Nabble.com.