[cfe-dev] "expression result unused" in comma expression
Chris Lattner
clattner at apple.com
Tue Aug 28 10:38:22 PDT 2007
On Aug 28, 2007, at 10:21 AM, Ted Kremenek wrote:
> A test case to the frontend generated the following unexpected
> warning:
>
> warning: expression result unused
> x = ++x, ++y, y+2;
> ^~~~~~~~~~~~~~~~~
>
> int comma_in_assignment(int x, int y) {
> x = ++x, ++y, y+2;
> return x;
> }
>
> Removing the "++x" also generates the same warning. Any thoughts? Is
> this desired behavior?
Note that this is parsed as:
(x = ++x), ++y, y+2;
$ clang t2.c -parse-ast-dump
int comma_in_assignment(int x, int y)
(CompoundStmt 0x2505e50
(BinaryOperator 0x2505dc0 'int' ','
(BinaryOperator 0x2505d40 'int' ','
(BinaryOperator 0x2505ce0 'int' '='
(DeclRefExpr 0x2505c80 'int' Decl='x' 0x2505c10)
(UnaryOperator 0x2505cc0 'int' prefix '++'
(DeclRefExpr 0x2505ca0 'int' Decl='x' 0x2505c10)))
(UnaryOperator 0x2505d20 'int' prefix '++'
(DeclRefExpr 0x2505d00 'int' Decl='y' 0x2505c40)))
(BinaryOperator 0x2505da0 'int' '+'
(DeclRefExpr 0x2505d60 'int' Decl='y' 0x2505c40)
(IntegerLiteral 0x2505d80 'int' 2)))
(ReturnStmt 0x2505e00
(DeclRefExpr 0x2501490 'int' Decl='x' 0x2505c10)))
So the y+2 is unused. I will fix the diagnostic to be more precise.
-Chris
More information about the cfe-dev
mailing list