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

Florin Iucha via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Sat Jan 11 21:26:25 PST 2020


0x8000-0000 added a comment.

One more mis-constification that I can't explain, nor reduce to a small test case (when I extract the code, the check behaves as expected / desired)

  namespace util {
    struct StringIgnoreInitialHash : public std::unary_function<std::string, size_t>
    {
       size_t operator()(const std::string& rhs) const
       {
          std::size_t hash = 0;
          std::string::const_iterator str = rhs.begin();
          std::string::const_iterator end = rhs.end();
          if (str != end)
          {
             boost::hash_combine(hash, std::toupper(*str, std::locale()));
             ++str;
          }
          for (; str != end; ++str)
          {
             boost::hash_combine(hash, *str);
          }
          return hash;
       }
    };
  }

This is in a header included 29 times in other headers and 106 times directly in translation units.

The const-checker reported 31 times that the variable 'hash' can be made constant.

Also it reported 5 times that the variable 'str' can be made constant (which it can't) and 194 times that variable 'end' can be made constant (which it can, and should).

Running in fix mode, made 'hash', 'str' and 'end' all constants.

Extracting this into its own translation unit and adding the requisite \#includes and paths to the boost files does not reproduce the error. Only 'end' is, correctly, reported as needing to be const.


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