www.digitalmars.com Home | Search | C & C++ | D | DMDScript | News Groups | index | prev | next
Archives

D Programming
D
D.gnu
digitalmars.D
digitalmars.D.bugs
digitalmars.D.dtl
digitalmars.D.dwt
digitalmars.D.announce
digitalmars.D.learn
digitalmars.D.debugger

C/C++ Programming
c++
c++.announce
c++.atl
c++.beta
c++.chat
c++.command-line
c++.dos
c++.dos.16-bits
c++.dos.32-bits
c++.idde
c++.mfc
c++.rtl
c++.stl
c++.stl.hp
c++.stl.port
c++.stl.sgi
c++.stlsoft
c++.windows
c++.windows.16-bits
c++.windows.32-bits
c++.wxwindows

digitalmars.empire
digitalmars.DMDScript

c++ - Possible bug in -wc ...

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