Only consider built-in compound assignment operators for -Wunused-but-set-*
authorStephan Bergmann <sbergman@redhat.com>
Mon, 14 Jun 2021 05:57:22 +0000 (07:57 +0200)
committerStephan Bergmann <sbergman@redhat.com>
Mon, 14 Jun 2021 06:04:03 +0000 (08:04 +0200)
commitb5b9489b2415dc48c39d4d7d4bae6197dc499f38
tree228bdf2531a3e69bfd1a13c79b7b134283528f46
parent8449af41e5c735960691f711ed9500c2a80a0b11
Only consider built-in compound assignment operators for -Wunused-but-set-*

At least LibreOffice has, for mainly historic reasons that would be hard to
change now, a class Any with an overloaded operator >>= that semantically does
not assign to the LHS but rather extracts into the (by-reference) RHS.  Which
thus caused false positive -Wunused-but-set-parameter and
-Wunused-but-set-variable after those have been introduced recently.

This change is more conservative about the assumed semantics of overloaded
operators, excluding compound assignment operators but keeping plain operator =
ones.  At least for LibreOffice, that strikes a good balance of not producing
false positives but still finding lots of true ones.

(The change to the BinaryOperator case in MaybeDecrementCount is necessary
because e.g. the template f4 test code in warn-unused-but-set-variables-cpp.cpp
turns the += into a BinaryOperator.)

Differential Revision: https://reviews.llvm.org/D103949
clang/lib/Sema/SemaExprCXX.cpp
clang/test/SemaCXX/warn-unused-but-set-variables-cpp.cpp