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

Florin Iucha via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Thu Oct 7 12:33:15 PDT 2021


0x8000-0000 added a comment.

In D54943#3048763 <https://reviews.llvm.org/D54943#3048763>, @JonasToth wrote:

> ping

Hi Jonas,

Using patch32 in production (on top of "release/13.x" branch) ever since it was made available. No crashes.

Only one false positive reported, which I'm not sure even is a false positive, is when I used std::visit and passed in a reference to an object as the first argument, the checker recommended I annotate the variable as const, even though std::visit takes the argument by &&, and changing it to const would have resulted in a miscompile. I think there's also some difference in how std::visit is implemented between various standard C++ libraries, so not sure if that's a special case or something more general.

Quoting from memory:

   std::variant<Foo, Bar, Baz> theThing;
  
   class Parameter
   {
      int operator()(const Foo& foo)
      {
       ...
      }
      int operator()(const Bar& bar)
      {
       ...
      }
   } param;  // cannot be const, but the checker warns that it could be const
  
  std::visit(param, theThing)

I'm hoping to have some time next week to distill a minimal test case.

Thank you,
florin


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