[all-commits] [llvm/llvm-project] f5fd74: [clang-tidy] New check readability-prefer-member-i...

Balogh, Ádám via All-commits all-commits at lists.llvm.org
Mon Aug 31 07:02:22 PDT 2020


  Branch: refs/heads/master
  Home:   https://github.com/llvm/llvm-project
  Commit: f5fd7486d6c0debb465de3e927fcc31884874280
      https://github.com/llvm/llvm-project/commit/f5fd7486d6c0debb465de3e927fcc31884874280
  Author: Adam Balogh <adam.balogh at ericsson.com>
  Date:   2020-08-31 (Mon, 31 Aug 2020)

  Changed paths:
    M clang-tools-extra/clang-tidy/cppcoreguidelines/CMakeLists.txt
    M clang-tools-extra/clang-tidy/cppcoreguidelines/CppCoreGuidelinesTidyModule.cpp
    A clang-tools-extra/clang-tidy/cppcoreguidelines/PreferMemberInitializerCheck.cpp
    A clang-tools-extra/clang-tidy/cppcoreguidelines/PreferMemberInitializerCheck.h
    M clang-tools-extra/docs/ReleaseNotes.rst
    A clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines-prefer-member-initializer.rst
    M clang-tools-extra/docs/clang-tidy/checks/list.rst
    A clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines-prefer-member-initializer-modernize-use-default-member-init-assignment.cpp
    A clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines-prefer-member-initializer-modernize-use-default-member-init.cpp
    A clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines-prefer-member-initializer.cpp

  Log Message:
  -----------
  [clang-tidy] New check readability-prefer-member-initializer

Finds member initializations in the constructor body which can
be placed to the member initializers of the constructor instead.
This does not only improves the readability of the code but also
affects positively its performance. Class-member assignments
inside a control statement or following the first control
statement are ignored.

Differential Revision: https://reviews.llvm.org/D71199


  Commit: 14dd0737822ba476803320a2ff37a1012174d312
      https://github.com/llvm/llvm-project/commit/14dd0737822ba476803320a2ff37a1012174d312
  Author: Adam Balogh <adam.balogh at ericsson.com>
  Date:   2020-08-31 (Mon, 31 Aug 2020)

  Changed paths:
    M clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp
    M clang-tools-extra/clang-tidy/bugprone/CMakeLists.txt
    A clang-tools-extra/clang-tidy/bugprone/RedundantBranchConditionCheck.cpp
    A clang-tools-extra/clang-tidy/bugprone/RedundantBranchConditionCheck.h
    M clang-tools-extra/docs/ReleaseNotes.rst
    A clang-tools-extra/docs/clang-tidy/checks/bugprone-redundant-branch-condition.rst
    M clang-tools-extra/docs/clang-tidy/checks/list.rst
    A clang-tools-extra/test/clang-tidy/checkers/bugprone-redundant-branch-condition.cpp

  Log Message:
  -----------
  [Clang-Tidy] New check `bugprone-redundant-branch-condition`

Checking the same condition again in a nested `if` usually make no sense,
except if the value of the expression could have been changed between
the two checks. Although compilers may optimize this out, such code is
suspicious: the programmer may have meant to check something else.
Therefore it is worth to find such places in the code and notify the
user about the problem.

This patch implements a basic check for this problem. Currently it
only detects redundant conditions where the condition is a variable of
integral type. It also detects the possible bug if the variable is in an
//or// or //and// logical expression in the inner if and/or the variable
is in an //and// logical expression in the outer if statement. Negated
cases are not handled yet.

Differential Revision: https://reviews.llvm.org/D81272


Compare: https://github.com/llvm/llvm-project/compare/1c9a09f42e5e...14dd0737822b


More information about the All-commits mailing list