"expression result unused" in comma expression

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

Thanks for pointing this out. On a related matter, it does appear that this check doesn't handle statement expressions (unless I'm, quite possibly, also reading this wrong!):

int maxval_stmt_expr(int x, int y) {
   return ({int _a = x, _b = y; _a > _b ? _a : _b; });
}

warning: expression result unused
   return ({int _a = x, _b = y; _a > _b ? _a : _b; });
                                ^~~~~~~~~~~~~~~~~

(it's pointing to the ternary expression)

So the y+2 is unused. I will fix the diagnostic to be more precise.

Thanks for pointing this out. On a related matter, it does appear that this check doesn't handle statement expressions (unless I'm, quite possibly, also reading this wrong!):

int maxval_stmt_expr(int x, int y) {
  return ({int _a = x, _b = y; _a > _b ? _a : _b; });
}

warning: expression result unused
  return ({int _a = x, _b = y; _a > _b ? _a : _b; });
                               ^~~~~~~~~~~~~~~~~

(it's pointing to the ternary expression)

You are right, it doesn't handle them yet. This is a bug in the warning that I haven't addressed yet.

-Chris

Fixed.

-Chris