6 ms·
It should be an error, not a warning (default or not). There are a number of things like this that should just not be accepted anymore. Here's another one:
by WalterBright 10y ago
It should be an error, not a warning (default or not). There are a number of things like this that should just not be accepted anymore. Here's another one:
if (condition);
dothis();
No compiler should accept that, regardless of switch settings.
- jacquesm 10y agoFully agreed. There is absolutely no way that is something a programmer ever intended. In fact I think that just if (condition); Should already be enough to trigger the error. (Any 'if' statement without a body).
- spacemanmatt 10y agoThere could be an important side-effect in condition. Isn't persistent state fun!?
- hasenj 10y agoIn that case an empty curly block would make the intention explicit.
- jacquesm 10y agoThat could still be a case of a dropped line in the body.
- shawabawa3 10y agoWhy have it in an if though?
- spacemanmatt 10y agoI am not condoning it, so much as noting what goes wrong when it's easy ;)
- dagw 10y agoIt should be an error, not a warning (default or not). In C++ you can overload '==' to do anything you want, including things that have side effects[0]. Without deeper introspection into the code, it's tricky to check if it's an error or not. [0] PS. Never do this!
- WalterBright 10y agoOverloading means calling a function, and is treated like calling a function.