Unused expression and comma operator

This issue is similar to that of conditional operator I raised before.
I concede that "a ? b : c" can be warned as unused expression even if
b or c have side effects, since computation done by ?: itself is
unused.

How about "a, b"?

#define luaZ_initbuffer(L, buff) ((buff)->buffer = NULL, (buff)->buffsize = 0)
luaZ_initbuffer(L, &p.buff);

Comma operators are often used in preprocessor macro. If "a, b" is
changed to "a; b", people who use macro as if it is function in codes
like "if (condition) macro(...)" without braces will get a nasty
surprise.

I think the standard way to replace "a, b" is "do { a; b; }
while(0);". But should this warn?

http://c2.com/cgi/wiki?TrivialDoWhileLoop discusses comma operators,
do while loop, and related tricks in detail.

This issue is similar to that of conditional operator I raised before.
I concede that "a ? b : c" can be warned as unused expression even if
b or c have side effects, since computation done by ?: itself is
unused.

Ok.

How about "a, b"?

I don't consider "," to be as clear-cut as "?:".

#define luaZ_initbuffer(L, buff) ((buff)->buffer = NULL, (buff)->buffsize = 0)
luaZ_initbuffer(L, &p.buff);

Comma operators are often used in preprocessor macro. If "a, b" is
changed to "a; b", people who use macro as if it is function in codes
like "if (condition) macro(...)" without braces will get a nasty
surprise.

I think the standard way to replace "a, b" is "do { a; b; }
while(0);". But should this warn?

http://c2.com/cgi/wiki?TrivialDoWhileLoop discusses comma operators,
do while loop, and related tricks in detail.

There are two different ways to handle this. One is to allow the comma operator. However, if a 'dead' comma is allowed, the checker should recursively check that no operands are unused expressions. We should warn on "foo(), 4+5;".

Alternatively, and probably better: just silence the warning if the operator is a comma that came from a macro expansion. You can check this by using SourceLocation::isMacroID() on the comma's location.

-Chris