[PATCH] D54943: [clang-tidy] implement const-transformation for cppcoreguidelines-const-correctness

Florin Iucha via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Fri Jan 10 19:34:23 PST 2020


0x8000-0000 added a comment.

Here is a minimal example that shows the problem:

  #include <memory>
  
  template<typename SomeValue>
  struct DoGooder
  {
      DoGooder(void* accessor, SomeValue value)
      {
      }
  
  };
  
  struct Bingus
  {
      static constexpr auto someRandomConstant = 99;
  };
  
  template<typename Foo>
  struct HardWorker
  {
      HardWorker()
      {
          const DoGooder anInstanceOf{nullptr, Foo::someRandomConstant};
      }
  };
  
  struct TheContainer
  {
      std::unique_ptr<HardWorker<Bingus>> m_theOtherInstance;
  };

Example run:

  $ /opt/clang10/bin/clang-tidy -checks="-*,cppcoreguidelines-const-correctness" -header-filter=".*" reproconst.cpp -- -std=c++17 -Wall
  54 warnings generated.
  reproconst.cpp:22:9: warning: variable 'anInstanceOf' of type '<dependent type>' can be declared 'const' [cppcoreguidelines-const-correctness]
          const DoGooder anInstanceOf{nullptr, Foo::someRandomConstant};
          ^
                         const
  Suppressed 53 warnings (53 in non-user code).
  Use -header-filter=.* to display errors from all non-system headers. Use -system-headers to display errors from system headers as well.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D54943/new/

https://reviews.llvm.org/D54943





More information about the cfe-commits mailing list