c++ - Possible bug in -wc ...
- Matthew Wilson (29/29) Jun 11 2003 I get a warning for the following line:
I get a warning for the following line: (void)::LocalFree(SyCastStatic(HLOCAL, pv)); SyCastStatic(T, V) resolves to static_cast<T>(V) for C++ compilation units (on compilers that support static_cast<>), so the cast applies to the elision of the accessibility of the return value. (I've checked this by removing the "(void)" from the statement. Irrespective of the anachronistic nature of the code, this is still a common idiom in some quarters, and should not be labelled as a "C-cast that should have been a C++-style cast", IMO. Any chance, of making this special case (i.e. a statement prefixed with (void), which itself is not prefixed by a lhs) and not throw up the warning? I'll give you a potentially more convincing case. Often it is convenient (albeit a bit hero-terse) to write something such as the following int setup_stuff(int x); int init_and_eval(int x) { return (x < 0) ? (setup_stuff(x), -x) : x; } This is a bit of a maintenance trap, and somewhat nicer to write int init_and_eval(int x) { return (x < 0) ? ((void)setup_stuff(x), -x) : x; } so that if anyone stuffs up the bracing and removes the ", -x", it'll fail to compile, rather than doing something unexpected. However, I guess on current evidence that it would throw the warning, which would be wrong in this case. Convinced ... ? :)
Jun 11 2003