[PATCH] D61749: [clang-tidy] initial version of readability-static-const-method

Matthias Gehre via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Thu May 9 12:06:44 PDT 2019


mgehre created this revision.
mgehre added reviewers: alexfh, aaron.ballman.
Herald added subscribers: xazax.hun, mgorny.
Herald added a project: clang.

Finds non-static member functions that can be made ``const`` or ``static``.
The check conservatively tries to preserve logical costness in favor of
physical costness. It will not recommend to make member functions ``const``
that call (const) member functions on a non-static data members,
e.g. ``std::unique_ptr::get`` because that might indicate logical
non-costness. Currently, it will only make member functions ``const`` if they
only access to ``this`` is to read members of builtin type.

I have run this check (repeatedly) over llvm-project. It made 1708 member functions
``static``. Out of those, I had to exclude 22 via ``NOLINT`` because their address
was taken and stored in a variable of pointer-to-member type (e.g. passed to
llvm::StringSwitch).
It also made 243 member functions ``const``. (This is currently very conservative
to have no false-positives and can hopefully be extended in the future.)

You can find the results here: https://github.com/mgehre/llvm-project/commits/static_const_eval


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D61749

Files:
  clang-tools-extra/clang-tidy/readability/CMakeLists.txt
  clang-tools-extra/clang-tidy/readability/ReadabilityTidyModule.cpp
  clang-tools-extra/clang-tidy/readability/StaticConstMethodCheck.cpp
  clang-tools-extra/clang-tidy/readability/StaticConstMethodCheck.h
  clang-tools-extra/docs/ReleaseNotes.rst
  clang-tools-extra/docs/clang-tidy/checks/list.rst
  clang-tools-extra/docs/clang-tidy/checks/readability-static-const-method.rst
  clang-tools-extra/test/clang-tidy/readability-static-const-method.cpp

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D61749.198882.patch
Type: text/x-patch
Size: 23084 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20190509/35ecafec/attachment-0001.bin>


More information about the cfe-commits mailing list