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

Jonas Toth via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Sat Jan 11 02:23:12 PST 2020


JonasToth added a comment.

In D54943#1815358 <https://reviews.llvm.org/D54943#1815358>, @0x8000-0000 wrote:

> 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.
>


I can not reproduce that case :(
It gives me a compilation error in `const DoGooder anInstanceOf...`, because `DoGooder` requires an template parameter. I then add `DoGooder<int>` and the variable gets no transformation.
Did you reproduce the error with exactly that code?

And which version did you run? Maybe that was a previous false positive, that might be fixed right now?


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