[PATCH] D125885: bugprone-argument-comment: Ignore calls to user-defined literals

Joachim Priesner via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Wed May 18 06:40:25 PDT 2022


jspam created this revision.
Herald added a subscriber: carlosgalvezp.
Herald added a project: All.
jspam requested review of this revision.
Herald added a project: clang-tools-extra.
Herald added a subscriber: cfe-commits.

Without this change, code such as "f(/*param=*/1_op)" will check the
comment twice, once for the parameter of f (correct) and once for
the parameter of operator""_op (likely incorrect). The change removes
only the second check.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D125885

Files:
  clang-tools-extra/clang-tidy/bugprone/ArgumentCommentCheck.cpp
  clang-tools-extra/test/clang-tidy/checkers/bugprone-argument-comment.cpp


Index: clang-tools-extra/test/clang-tidy/checkers/bugprone-argument-comment.cpp
===================================================================
--- clang-tools-extra/test/clang-tidy/checkers/bugprone-argument-comment.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/bugprone-argument-comment.cpp
@@ -5,6 +5,8 @@
 
 void ffff(int xxxx, int yyyy);
 
+int operator""_op(unsigned long long val);
+
 void f(int x, int y);
 void g() {
   // CHECK-NOTES: [[@LINE+4]]:5: warning: argument name 'y' in comment does not match parameter name 'x'
@@ -14,7 +16,15 @@
   f(/*y=*/0, /*z=*/0);
   // CHECK-FIXES: {{^}}  f(/*y=*/0, /*z=*/0);
 
+  // CHECK-NOTES: [[@LINE+4]]:5: warning: argument name 'y' in comment does not match parameter name 'x'
+  // CHECK-NOTES: [[@LINE-10]]:12: note: 'x' declared here
+  // CHECK-NOTES: [[@LINE+2]]:14: warning: argument name 'z' in comment does not match parameter name 'y'
+  // CHECK-NOTES: [[@LINE-12]]:19: note: 'y' declared here
+  f(/*y=*/0_op, /*z=*/0_op);
+  // CHECK-FIXES: {{^}}  f(/*y=*/0_op, /*z=*/0_op);
+
   f(/*x=*/1, /*y=*/1);
+  f(/*x=*/1_op, /*y=*/1_op);
 
   ffff(0 /*aaaa=*/, /*bbbb*/ 0); // Unsupported formats.
 }
Index: clang-tools-extra/clang-tidy/bugprone/ArgumentCommentCheck.cpp
===================================================================
--- clang-tools-extra/clang-tidy/bugprone/ArgumentCommentCheck.cpp
+++ clang-tools-extra/clang-tidy/bugprone/ArgumentCommentCheck.cpp
@@ -60,7 +60,7 @@
 
 void ArgumentCommentCheck::registerMatchers(MatchFinder *Finder) {
   Finder->addMatcher(
-      callExpr(unless(cxxOperatorCallExpr()),
+      callExpr(unless(cxxOperatorCallExpr()), unless(userDefinedLiteral()),
                // NewCallback's arguments relate to the pointed function,
                // don't check them against NewCallback's parameter names.
                // FIXME: Make this configurable.


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D125885.430362.patch
Type: text/x-patch
Size: 1875 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20220518/20cd3223/attachment.bin>


More information about the cfe-commits mailing list