[all-commits] [llvm/llvm-project] b5b948: Only consider built-in compound assignment operato...

stbergmann via All-commits all-commits at lists.llvm.org
Sun Jun 13 23:04:22 PDT 2021


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: b5b9489b2415dc48c39d4d7d4bae6197dc499f38
      https://github.com/llvm/llvm-project/commit/b5b9489b2415dc48c39d4d7d4bae6197dc499f38
  Author: Stephan Bergmann <sbergman at redhat.com>
  Date:   2021-06-14 (Mon, 14 Jun 2021)

  Changed paths:
    M clang/lib/Sema/SemaExprCXX.cpp
    M clang/test/SemaCXX/warn-unused-but-set-variables-cpp.cpp

  Log Message:
  -----------
  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




More information about the All-commits mailing list