Observe that we evaluate index() (and save it) before evaluating the
ternary expression. Since "(void) SAVE_EXPR <index ()>" is ostensibly
side-effect free, we get this warning. Since SAVE_EXPR is not useless,
this is a false positive. Also the comma operator compiler-generated,
so warning about it is wrong.
Suppress this warning for this implicit expression. Test that the
warning is gone for "$ternary[index()]" but we still warn on cases like
"$ternary[(1, 0)]".
gcc/cp/ChangeLog:
* typeck.cc (cp_build_array_ref): Suppress unused-value
warning for implicit comma expression.
gcc/testsuite/ChangeLog:
* g++.dg/warn/Wunused-value-2.C: New test.
Signed-off-by: Johannes Altmanninger <aclopte@gmail.com> Co-authored-by: Jason Merrill <jason@redhat.com>