[clang-tools-extra] [clang-tidy] add modernize-use-std-numbers (PR #66583)

Julian Schmidt via cfe-commits cfe-commits at lists.llvm.org
Wed Dec 6 10:28:58 PST 2023


5chmidti wrote:

@PiotrZSL check out https://lab.llvm.org/buildbot/#/builders/230/builds/22226, the bot was red on previous runs, but those are unrelated to how it fails now. The bot fails for this patch with the following build failure:
```
/home/buildbots/ppc64le-clang-test-suite/clang-ppc64le-test-suite/llvm-project/clang-tools-extra/clang-tidy/modernize/UseStdNumbersCheck.cpp: In member function ‘virtual void clang::tidy::modernize::UseStdNumbersCheck::registerMatchers(clang::ast_matchers::MatchFinder*)’:
/home/buildbots/ppc64le-clang-test-suite/clang-ppc64le-test-suite/llvm-project/clang-tools-extra/clang-tidy/modernize/UseStdNumbersCheck.cpp:319:27: error: invalid initialization of reference of type ‘const llvm::ArrayRef<clang::ast_matchers::internal::Matcher<clang::Stmt> >&’ from expression of type ‘const std::initializer_list<const clang::ast_matchers::internal::Matcher<clang::Stmt> >’
           anyOfExhaustive(ConstantMatchers),
                           ^~~~~~~~~~~~~~~~
In file included from /home/buildbots/ppc64le-clang-test-suite/clang-ppc64le-test-suite/llvm-project/clang/include/clang/ASTMatchers/ASTMatchers.h:73,
                 from /home/buildbots/ppc64le-clang-test-suite/clang-ppc64le-test-suite/llvm-project/clang/include/clang/ASTMatchers/ASTMatchFinder.h:43,
                 from /home/buildbots/ppc64le-clang-test-suite/clang-ppc64le-test-suite/llvm-project/clang-tools-extra/clang-tidy/modernize/../ClangTidyCheck.h:14,
                 from /home/buildbots/ppc64le-clang-test-suite/clang-ppc64le-test-suite/llvm-project/clang-tools-extra/clang-tidy/modernize/UseStdNumbersCheck.h:12,
                 from /home/buildbots/ppc64le-clang-test-suite/clang-ppc64le-test-suite/llvm-project/clang-tools-extra/clang-tidy/modernize/UseStdNumbersCheck.cpp:9:
/home/buildbots/ppc64le-clang-test-suite/clang-ppc64le-test-suite/llvm-project/clang-tools-extra/clang-tidy/modernize/UseStdNumbersCheck.cpp:64:28: note: in passing argument 1 of ‘clang::ast_matchers::internal::Matcher<clang::Expr> {anonymous}::anyOfExhaustive(const llvm::ArrayRef<clang::ast_matchers::internal::Matcher<clang::Stmt> >&)’
 AST_MATCHER_P(clang::Expr, anyOfExhaustive,
                            ^~~~~~~~~~~~~~~
/home/buildbots/ppc64le-clang-test-suite/clang-ppc64le-test-suite/llvm-project/clang/include/clang/ASTMatchers/ASTMatchersMacros.h:149:57: note: in definition of macro ‘AST_MATCHER_P_OVERLOAD’
   inline ::clang::ast_matchers::internal::Matcher<Type> DefineMatcher(         \
                                                         ^~~~~~~~~~~~~
/home/buildbots/ppc64le-clang-test-suite/clang-ppc64le-test-suite/llvm-project/clang-tools-extra/clang-tidy/modernize/UseStdNumbersCheck.cpp:64:1: note: in expansion of macro ‘AST_MATCHER_P’
 AST_MATCHER_P(clang::Expr, anyOfExhaustive,
 ^~~~~~~~~~~~~
```

The mismatch happens for the template arguments of `ArrayRef` and `initializer_list` in `anyOfExhaustive`:
`const llvm::ArrayRef<clang::ast_matchers::internal::Matcher<clang::Stmt> >&`
`const std::initializer_list<const clang::ast_matchers::internal::Matcher<clang::Stmt> >`

I think the easiest fix is to add `const` to the `ArrayRef` in `anyOfExhaustive` like so:
```c++
AST_MATCHER_P(clang::Expr, anyOfExhaustive,
              llvm::ArrayRef<const Matcher<clang::Stmt>>, Exprs) {
```

https://github.com/llvm/llvm-project/blob/65cb5d58eb5783c17fd2121db79ebac950b767b2/clang-tools-extra/clang-tidy/modernize/UseStdNumbersCheck.cpp#L64-L75

FYI I don't have write access, so I cannot push a fix myself. Or just revert?
What do you think?

https://github.com/llvm/llvm-project/pull/66583


More information about the cfe-commits mailing list