[clang-tools-extra] [clang-tidy] Ignore user-defined literals in google-runtime-int (PR #78859)

Piotr Zegar via cfe-commits cfe-commits at lists.llvm.org
Sat Jan 20 13:54:26 PST 2024


================
@@ -56,11 +56,14 @@ void IntegerTypesCheck::registerMatchers(MatchFinder *Finder) {
   // http://google.github.io/styleguide/cppguide.html#64-bit_Portability
   // "Where possible, avoid passing arguments of types specified by
   // bitwidth typedefs to printf-based APIs."
-  Finder->addMatcher(typeLoc(loc(isInteger()),
-                             unless(hasAncestor(callExpr(
-                                 callee(functionDecl(hasAttr(attr::Format)))))))
-                         .bind("tl"),
-                     this);
+  Finder->addMatcher(
+      typeLoc(loc(isInteger()),
+              unless(anyOf(hasAncestor(callExpr(
+                               callee(functionDecl(hasAttr(attr::Format))))),
+                           hasParent(parmVarDecl(hasAncestor(functionDecl(
+                               matchesName("operator\"\".*$"))))))))
----------------
PiotrZSL wrote:

may work, but better would be to write AST_MATCHER that would utilize this:
/// getLiteralIdentifier - The literal suffix identifier this function
/// represents, if any.
const [IdentifierInfo](https://clang.llvm.org/doxygen/classclang_1_1IdentifierInfo.html) *[FunctionDecl::getLiteralIdentifier](https://clang.llvm.org/doxygen/classclang_1_1FunctionDecl.html#abff3536d50f040b6e96c52744a79736c)() const {
  if ([getDeclName](https://clang.llvm.org/doxygen/classclang_1_1NamedDecl.html#a62f956edf003453d95cff6384168c071)().getNameKind() == [DeclarationName::CXXLiteralOperatorName](https://clang.llvm.org/doxygen/classclang_1_1DeclarationName.html#a9ab322d434446b43379d39e41af5cbe3a72a534aca2e192f3fcc66c34c16e7e19))
    return [getDeclName](https://clang.llvm.org/doxygen/classclang_1_1NamedDecl.html#a62f956edf003453d95cff6384168c071)().[getCXXLiteralIdentifier](https://clang.llvm.org/doxygen/classclang_1_1DeclarationName.html#a63cdc12bea65df4ea28af50ca280c2fe)();
  return nullptr;
}

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


More information about the cfe-commits mailing list