[clang-tools-extra] [clang-tidy] comment braced-init list arguments (PR #180408)
Daniil Dudkin via cfe-commits
cfe-commits at lists.llvm.org
Sun Mar 29 13:45:42 PDT 2026
https://github.com/unterumarmung updated https://github.com/llvm/llvm-project/pull/180408
>From c3271b607bc558c1ff5be82c56efd56c53230a6a Mon Sep 17 00:00:00 2001
From: Daniil Dudkin <unterumarmung at yandex.ru>
Date: Sun, 15 Mar 2026 23:39:29 +0300
Subject: [PATCH 1/3] clang-tidy: comment braced-init list arguments
---
.../bugprone/ArgumentCommentCheck.cpp | 60 +++++++++-
.../bugprone/ArgumentCommentCheck.h | 2 +
clang-tools-extra/docs/ReleaseNotes.rst | 9 +-
.../checks/bugprone/argument-comment.rst | 44 ++++++++
.../argument-comment-init-list-cxx20.cpp | 48 ++++++++
.../bugprone/argument-comment-init-list.cpp | 104 ++++++++++++++++++
.../bugprone/argument-comment-literals.cpp | 1 -
7 files changed, 261 insertions(+), 7 deletions(-)
create mode 100644 clang-tools-extra/test/clang-tidy/checkers/bugprone/argument-comment-init-list-cxx20.cpp
create mode 100644 clang-tools-extra/test/clang-tidy/checkers/bugprone/argument-comment-init-list.cpp
diff --git a/clang-tools-extra/clang-tidy/bugprone/ArgumentCommentCheck.cpp b/clang-tools-extra/clang-tidy/bugprone/ArgumentCommentCheck.cpp
index e3139f96cfb09..8b16dae8a6051 100644
--- a/clang-tools-extra/clang-tidy/bugprone/ArgumentCommentCheck.cpp
+++ b/clang-tools-extra/clang-tidy/bugprone/ArgumentCommentCheck.cpp
@@ -43,6 +43,9 @@ ArgumentCommentCheck::ArgumentCommentCheck(StringRef Name,
CommentUserDefinedLiterals(
Options.get("CommentUserDefinedLiterals", false)),
CommentCharacterLiterals(Options.get("CommentCharacterLiterals", false)),
+ CommentAnonymousInitLists(
+ Options.get("CommentAnonymousInitLists", false)),
+ CommentTypedInitLists(Options.get("CommentTypedInitLists", false)),
CommentNullPtrs(Options.get("CommentNullPtrs", false)),
IdentRE("^(/\\* *)([_A-Za-z][_A-Za-z0-9]*)( *= *\\*/)$") {}
@@ -55,6 +58,8 @@ void ArgumentCommentCheck::storeOptions(ClangTidyOptions::OptionMap &Opts) {
Options.store(Opts, "CommentStringLiterals", CommentStringLiterals);
Options.store(Opts, "CommentUserDefinedLiterals", CommentUserDefinedLiterals);
Options.store(Opts, "CommentCharacterLiterals", CommentCharacterLiterals);
+ Options.store(Opts, "CommentAnonymousInitLists", CommentAnonymousInitLists);
+ Options.store(Opts, "CommentTypedInitLists", CommentTypedInitLists);
Options.store(Opts, "CommentNullPtrs", CommentNullPtrs);
}
@@ -199,15 +204,62 @@ static const FunctionDecl *resolveMocks(const FunctionDecl *Func) {
return Func;
}
+namespace {
+
+enum class InitListKind {
+ None,
+ Anonymous,
+ Typed,
+};
+
+} // namespace
+
+static InitListKind getInitListKind(const Expr *Arg) {
+ Arg = Arg->IgnoreImplicit();
+
+ // Peel std::initializer_list wrappers until we reach the underlying
+ // list-initialization expression.
+ while (const auto *StdInit = dyn_cast<CXXStdInitializerListExpr>(Arg))
+ Arg = StdInit->getSubExpr()->IgnoreImplicit();
+
+ if (isa<InitListExpr>(Arg))
+ return InitListKind::Anonymous;
+
+ if (const auto *Ctor = dyn_cast<CXXConstructExpr>(Arg)) {
+ if (!Ctor->isListInitialization())
+ return InitListKind::None;
+ // CXXTemporaryObjectExpr corresponds to explicit Type{...} syntax.
+ if (isa<CXXTemporaryObjectExpr>(Ctor))
+ return InitListKind::Typed;
+ // Other list-initialized constructions (for example '{}') have no
+ // explicit type at the call site.
+ return InitListKind::Anonymous;
+ }
+
+ if (const auto *FuncCast = dyn_cast<CXXFunctionalCastExpr>(Arg)) {
+ if (FuncCast->isListInitialization())
+ return InitListKind::Typed;
+ }
+
+ return InitListKind::None;
+}
+
// Given the argument type and the options determine if we should
// be adding an argument comment.
bool ArgumentCommentCheck::shouldAddComment(const Expr *Arg) const {
- Arg = Arg->IgnoreImpCasts();
- if (isa<UnaryOperator>(Arg))
- Arg = cast<UnaryOperator>(Arg)->getSubExpr();
+ // Strip implicit wrappers so brace-init arguments bound to references still
+ // look like list-initialization at this point.
+ Arg = Arg->IgnoreImplicit();
+ if (const auto *UO = dyn_cast<UnaryOperator>(Arg))
+ Arg = UO->getSubExpr()->IgnoreImplicit();
if (Arg->getExprLoc().isMacroID())
return false;
- return (CommentBoolLiterals && isa<CXXBoolLiteralExpr>(Arg)) ||
+
+ const InitListKind Kind = getInitListKind(Arg);
+
+ return (CommentAnonymousInitLists && Kind == InitListKind::Anonymous) ||
+ (CommentTypedInitLists && Kind == InitListKind::Typed) ||
+ (CommentBoolLiterals && isa<CXXBoolLiteralExpr>(Arg)) ||
(CommentIntegerLiterals && isa<IntegerLiteral>(Arg)) ||
(CommentFloatLiterals && isa<FloatingLiteral>(Arg)) ||
(CommentUserDefinedLiterals && isa<UserDefinedLiteral>(Arg)) ||
diff --git a/clang-tools-extra/clang-tidy/bugprone/ArgumentCommentCheck.h b/clang-tools-extra/clang-tidy/bugprone/ArgumentCommentCheck.h
index 30fa32fad72e7..60a1338233f66 100644
--- a/clang-tools-extra/clang-tidy/bugprone/ArgumentCommentCheck.h
+++ b/clang-tools-extra/clang-tidy/bugprone/ArgumentCommentCheck.h
@@ -46,6 +46,8 @@ class ArgumentCommentCheck : public ClangTidyCheck {
const unsigned CommentStringLiterals : 1;
const unsigned CommentUserDefinedLiterals : 1;
const unsigned CommentCharacterLiterals : 1;
+ const unsigned CommentAnonymousInitLists : 1;
+ const unsigned CommentTypedInitLists : 1;
const unsigned CommentNullPtrs : 1;
llvm::Regex IdentRE;
diff --git a/clang-tools-extra/docs/ReleaseNotes.rst b/clang-tools-extra/docs/ReleaseNotes.rst
index eb735e6e62ee4..216d878d05c39 100644
--- a/clang-tools-extra/docs/ReleaseNotes.rst
+++ b/clang-tools-extra/docs/ReleaseNotes.rst
@@ -193,8 +193,13 @@ Changes in existing checks
^^^^^^^^^^^^^^^^^^^^^^^^^^
- Improved :doc:`bugprone-argument-comment
- <clang-tidy/checks/bugprone/argument-comment>` to also check for C++11
- inherited constructors.
+ <clang-tidy/checks/bugprone/argument-comment>`:
+
+ - Checks for C++11 inherited constructors.
+
+ - Adds `CommentAnonymousInitLists` and `CommentTypedInitLists` options
+ to comment braced-init list arguments (for example, ``{}`` and
+ ``Type{}``).
- Improved :doc:`bugprone-bad-signal-to-kill-thread
<clang-tidy/checks/bugprone/bad-signal-to-kill-thread>` check by fixing false
diff --git a/clang-tools-extra/docs/clang-tidy/checks/bugprone/argument-comment.rst b/clang-tools-extra/docs/clang-tidy/checks/bugprone/argument-comment.rst
index 8770d7224137a..dc028cde2fcc4 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/bugprone/argument-comment.rst
+++ b/clang-tools-extra/docs/clang-tidy/checks/bugprone/argument-comment.rst
@@ -146,6 +146,50 @@ After:
foo(/*Character=*/'A');
+.. option:: CommentAnonymousInitLists
+
+ When `true`, the check will add argument comments in the format
+ ``/*ParameterName=*/`` right before anonymous braced-init list arguments
+ such as ``{}`` and ``{1, 2, 3}``. Default is `false`.
+
+Before:
+
+.. code-block:: c++
+
+ void foo(const std::vector<int> &Dims);
+
+ foo({});
+
+After:
+
+.. code-block:: c++
+
+ void foo(const std::vector<int> &Dims);
+
+ foo(/*Dims=*/{});
+
+.. option:: CommentTypedInitLists
+
+ When `true`, the check will add argument comments in the format
+ ``/*ParameterName=*/`` right before typed braced-init list arguments such
+ as ``Type{}``. Default is `false`.
+
+Before:
+
+.. code-block:: c++
+
+ void foo(const std::vector<int> &Dims);
+
+ foo(std::vector<int>{});
+
+After:
+
+.. code-block:: c++
+
+ void foo(const std::vector<int> &Dims);
+
+ foo(/*Dims=*/std::vector<int>{});
+
.. option:: CommentUserDefinedLiterals
When `true`, the check will add argument comments in the format
diff --git a/clang-tools-extra/test/clang-tidy/checkers/bugprone/argument-comment-init-list-cxx20.cpp b/clang-tools-extra/test/clang-tidy/checkers/bugprone/argument-comment-init-list-cxx20.cpp
new file mode 100644
index 0000000000000..bcb1f7c68cd74
--- /dev/null
+++ b/clang-tools-extra/test/clang-tidy/checkers/bugprone/argument-comment-init-list-cxx20.cpp
@@ -0,0 +1,48 @@
+// RUN: %check_clang_tidy -check-suffix=OFF -std=c++20-or-later %s bugprone-argument-comment %t
+// RUN: %check_clang_tidy -check-suffix=ANON -std=c++20-or-later %s bugprone-argument-comment %t -- \
+// RUN: -config="{CheckOptions: { \
+// RUN: bugprone-argument-comment.CommentAnonymousInitLists: true}}" --
+// RUN: %check_clang_tidy -check-suffix=TYPED -std=c++20-or-later %s bugprone-argument-comment %t -- \
+// RUN: -config="{CheckOptions: { \
+// RUN: bugprone-argument-comment.CommentTypedInitLists: true}}" --
+// RUN: %check_clang_tidy -check-suffix=BOTH -std=c++20-or-later %s bugprone-argument-comment %t -- \
+// RUN: -config="{CheckOptions: { \
+// RUN: bugprone-argument-comment.CommentAnonymousInitLists: true, \
+// RUN: bugprone-argument-comment.CommentTypedInitLists: true}}" --
+
+namespace GH171842 {
+
+struct T {
+ int value;
+};
+
+struct Agg {
+ int x;
+ int y;
+};
+
+void foo_designated(T some_arg, const Agg &dims);
+
+void test_designated_init() {
+ T some_arg{0};
+
+ foo_designated(some_arg, /*dim=*/Agg{.x = 1});
+ // CHECK-MESSAGES-OFF: warning: argument name 'dim' in comment does not match parameter name 'dims'
+ // CHECK-FIXES-OFF: foo_designated(some_arg, /*dims=*/Agg{.x = 1});
+ // CHECK-MESSAGES-ANON: warning: argument name 'dim' in comment does not match parameter name 'dims'
+ // CHECK-FIXES-ANON: foo_designated(some_arg, /*dims=*/Agg{.x = 1});
+ // CHECK-MESSAGES-TYPED: warning: argument name 'dim' in comment does not match parameter name 'dims'
+ // CHECK-FIXES-TYPED: foo_designated(some_arg, /*dims=*/Agg{.x = 1});
+ // CHECK-MESSAGES-BOTH: warning: argument name 'dim' in comment does not match parameter name 'dims'
+ // CHECK-FIXES-BOTH: foo_designated(some_arg, /*dims=*/Agg{.x = 1});
+
+ foo_designated(some_arg, Agg{.x = 1});
+ // CHECK-MESSAGES-OFF-NOT: :[[@LINE-1]]:28: warning: argument comment missing for literal argument 'dims'
+ // CHECK-MESSAGES-ANON-NOT: :[[@LINE-2]]:28: warning: argument comment missing for literal argument 'dims'
+ // CHECK-MESSAGES-TYPED: [[@LINE-3]]:28: warning: argument comment missing for literal argument 'dims' [bugprone-argument-comment]
+ // CHECK-FIXES-TYPED: foo_designated(some_arg, /*dims=*/Agg{.x = 1});
+ // CHECK-MESSAGES-BOTH: [[@LINE-5]]:28: warning: argument comment missing for literal argument 'dims' [bugprone-argument-comment]
+ // CHECK-FIXES-BOTH: foo_designated(some_arg, /*dims=*/Agg{.x = 1});
+}
+
+} // namespace GH171842
diff --git a/clang-tools-extra/test/clang-tidy/checkers/bugprone/argument-comment-init-list.cpp b/clang-tools-extra/test/clang-tidy/checkers/bugprone/argument-comment-init-list.cpp
new file mode 100644
index 0000000000000..a3238a5cb4871
--- /dev/null
+++ b/clang-tools-extra/test/clang-tidy/checkers/bugprone/argument-comment-init-list.cpp
@@ -0,0 +1,104 @@
+// RUN: %check_clang_tidy -check-suffix=OFF %s bugprone-argument-comment %t
+// RUN: %check_clang_tidy -check-suffix=ANON %s bugprone-argument-comment %t -- \
+// RUN: -config="{CheckOptions: { \
+// RUN: bugprone-argument-comment.CommentAnonymousInitLists: true}}" --
+// RUN: %check_clang_tidy -check-suffix=TYPED %s bugprone-argument-comment %t -- \
+// RUN: -config="{CheckOptions: { \
+// RUN: bugprone-argument-comment.CommentTypedInitLists: true}}" --
+// RUN: %check_clang_tidy -check-suffix=BOTH %s bugprone-argument-comment %t -- \
+// RUN: -config="{CheckOptions: { \
+// RUN: bugprone-argument-comment.CommentAnonymousInitLists: true, \
+// RUN: bugprone-argument-comment.CommentTypedInitLists: true}}" --
+
+#include <initializer_list>
+#include <vector>
+
+namespace GH171842 {
+
+struct T {
+ int value;
+};
+
+void foo(T some_arg, const std::vector<int> &dims);
+void foo_init_list(T some_arg, std::initializer_list<int> dims);
+template <typename ElemTy>
+void foo_template(T some_arg, const std::vector<ElemTy> &dims);
+
+void test_braced_init_list() {
+ T some_arg{0};
+
+ // Mismatched explicit argument comments are validated independently of the
+ // init-list literal comment options.
+ foo(some_arg, /*dim=*/{});
+ // CHECK-MESSAGES-OFF: warning: argument name 'dim' in comment does not match parameter name 'dims'
+ // CHECK-FIXES-OFF: foo(some_arg, /*dims=*/{});
+ // CHECK-MESSAGES-ANON: warning: argument name 'dim' in comment does not match parameter name 'dims'
+ // CHECK-FIXES-ANON: foo(some_arg, /*dims=*/{});
+ // CHECK-MESSAGES-TYPED: warning: argument name 'dim' in comment does not match parameter name 'dims'
+ // CHECK-FIXES-TYPED: foo(some_arg, /*dims=*/{});
+ // CHECK-MESSAGES-BOTH: warning: argument name 'dim' in comment does not match parameter name 'dims'
+ // CHECK-FIXES-BOTH: foo(some_arg, /*dims=*/{});
+
+ foo(some_arg, /*dim=*/std::vector<int>{});
+ // CHECK-MESSAGES-OFF: warning: argument name 'dim' in comment does not match parameter name 'dims'
+ // CHECK-FIXES-OFF: foo(some_arg, /*dims=*/std::vector<int>{});
+ // CHECK-MESSAGES-ANON: warning: argument name 'dim' in comment does not match parameter name 'dims'
+ // CHECK-FIXES-ANON: foo(some_arg, /*dims=*/std::vector<int>{});
+ // CHECK-MESSAGES-TYPED: warning: argument name 'dim' in comment does not match parameter name 'dims'
+ // CHECK-FIXES-TYPED: foo(some_arg, /*dims=*/std::vector<int>{});
+ // CHECK-MESSAGES-BOTH: warning: argument name 'dim' in comment does not match parameter name 'dims'
+ // CHECK-FIXES-BOTH: foo(some_arg, /*dims=*/std::vector<int>{});
+
+ foo(some_arg, {});
+ // CHECK-MESSAGES-OFF-NOT: :[[@LINE-1]]:17: warning: argument comment missing for literal argument 'dims'
+ // CHECK-MESSAGES-ANON: [[@LINE-2]]:17: warning: argument comment missing for literal argument 'dims' [bugprone-argument-comment]
+ // CHECK-FIXES-ANON: foo(some_arg, /*dims=*/{});
+ // CHECK-MESSAGES-TYPED-NOT: :[[@LINE-4]]:17: warning: argument comment missing for literal argument 'dims'
+ // CHECK-MESSAGES-BOTH: [[@LINE-5]]:17: warning: argument comment missing for literal argument 'dims' [bugprone-argument-comment]
+ // CHECK-FIXES-BOTH: foo(some_arg, /*dims=*/{});
+
+ foo(some_arg, std::vector<int>{});
+ // CHECK-MESSAGES-OFF-NOT: :[[@LINE-1]]:17: warning: argument comment missing for literal argument 'dims'
+ // CHECK-MESSAGES-ANON-NOT: :[[@LINE-2]]:17: warning: argument comment missing for literal argument 'dims'
+ // CHECK-MESSAGES-TYPED: [[@LINE-3]]:17: warning: argument comment missing for literal argument 'dims' [bugprone-argument-comment]
+ // CHECK-FIXES-TYPED: foo(some_arg, /*dims=*/std::vector<int>{});
+ // CHECK-MESSAGES-BOTH: [[@LINE-5]]:17: warning: argument comment missing for literal argument 'dims' [bugprone-argument-comment]
+ // CHECK-FIXES-BOTH: foo(some_arg, /*dims=*/std::vector<int>{});
+}
+
+void test_initializer_list() {
+ T some_arg{0};
+
+ foo_init_list(some_arg, {1, 2, 3});
+ // CHECK-MESSAGES-OFF-NOT: :[[@LINE-1]]:27: warning: argument comment missing for literal argument 'dims'
+ // CHECK-MESSAGES-ANON: [[@LINE-2]]:27: warning: argument comment missing for literal argument 'dims' [bugprone-argument-comment]
+ // CHECK-FIXES-ANON: foo_init_list(some_arg, /*dims=*/{1, 2, 3});
+ // CHECK-MESSAGES-TYPED-NOT: :[[@LINE-4]]:27: warning: argument comment missing for literal argument 'dims'
+ // CHECK-MESSAGES-BOTH: [[@LINE-5]]:27: warning: argument comment missing for literal argument 'dims' [bugprone-argument-comment]
+ // CHECK-FIXES-BOTH: foo_init_list(some_arg, /*dims=*/{1, 2, 3});
+}
+
+template <typename ElemTy>
+void test_template_dependent_init_list() {
+ T some_arg{0};
+
+ foo_template<ElemTy>(some_arg, {});
+ // CHECK-MESSAGES-OFF-NOT: :[[@LINE-1]]:34: warning: argument comment missing for literal argument 'dims'
+ // CHECK-MESSAGES-ANON: [[@LINE-2]]:34: warning: argument comment missing for literal argument 'dims' [bugprone-argument-comment]
+ // CHECK-FIXES-ANON: foo_template<ElemTy>(some_arg, /*dims=*/{});
+ // CHECK-MESSAGES-TYPED-NOT: :[[@LINE-4]]:34: warning: argument comment missing for literal argument 'dims'
+ // CHECK-MESSAGES-BOTH: [[@LINE-5]]:34: warning: argument comment missing for literal argument 'dims' [bugprone-argument-comment]
+ // CHECK-FIXES-BOTH: foo_template<ElemTy>(some_arg, /*dims=*/{});
+
+ foo_template<ElemTy>(some_arg, std::vector<ElemTy>{});
+ // CHECK-MESSAGES-OFF-NOT: :[[@LINE-1]]:34: warning: argument comment missing for literal argument 'dims'
+ // CHECK-MESSAGES-ANON-NOT: :[[@LINE-2]]:34: warning: argument comment missing for literal argument 'dims'
+ // CHECK-MESSAGES-TYPED: [[@LINE-3]]:34: warning: argument comment missing for literal argument 'dims' [bugprone-argument-comment]
+ // CHECK-FIXES-TYPED: foo_template<ElemTy>(some_arg, /*dims=*/std::vector<ElemTy>{});
+ // CHECK-MESSAGES-BOTH: [[@LINE-5]]:34: warning: argument comment missing for literal argument 'dims' [bugprone-argument-comment]
+ // CHECK-FIXES-BOTH: foo_template<ElemTy>(some_arg, /*dims=*/std::vector<ElemTy>{});
+}
+
+template void test_template_dependent_init_list<int>();
+
+} // namespace GH171842
diff --git a/clang-tools-extra/test/clang-tidy/checkers/bugprone/argument-comment-literals.cpp b/clang-tools-extra/test/clang-tidy/checkers/bugprone/argument-comment-literals.cpp
index f03488a14d9f5..41283f66a2f26 100644
--- a/clang-tools-extra/test/clang-tidy/checkers/bugprone/argument-comment-literals.cpp
+++ b/clang-tools-extra/test/clang-tidy/checkers/bugprone/argument-comment-literals.cpp
@@ -7,7 +7,6 @@
// RUN: bugprone-argument-comment.CommentStringLiterals: true, \
// RUN: bugprone-argument-comment.CommentNullPtrs: true, \
// RUN: bugprone-argument-comment.CommentCharacterLiterals: true}}" --
-
struct A {
void foo(bool abc);
void foo(bool abc, bool cde);
>From 2a8dbe1936ca5c0bd26759b33091f3d6091360ad Mon Sep 17 00:00:00 2001
From: Daniil Dudkin <unterumarmung at yandex.ru>
Date: Mon, 16 Mar 2026 01:14:01 +0300
Subject: [PATCH 2/3] Address review comments and fix bug
---
.../bugprone/ArgumentCommentCheck.cpp | 18 ++++----
.../argument-comment-init-list-cxx20.cpp | 4 --
.../bugprone/argument-comment-init-list.cpp | 42 +++++++++++++++++--
.../bugprone/argument-comment-literals.cpp | 1 +
4 files changed, 49 insertions(+), 16 deletions(-)
diff --git a/clang-tools-extra/clang-tidy/bugprone/ArgumentCommentCheck.cpp b/clang-tools-extra/clang-tidy/bugprone/ArgumentCommentCheck.cpp
index 8b16dae8a6051..94190999984af 100644
--- a/clang-tools-extra/clang-tidy/bugprone/ArgumentCommentCheck.cpp
+++ b/clang-tools-extra/clang-tidy/bugprone/ArgumentCommentCheck.cpp
@@ -215,12 +215,10 @@ enum class InitListKind {
} // namespace
static InitListKind getInitListKind(const Expr *Arg) {
- Arg = Arg->IgnoreImplicit();
+ Arg = Arg->IgnoreUnlessSpelledInSource();
- // Peel std::initializer_list wrappers until we reach the underlying
- // list-initialization expression.
- while (const auto *StdInit = dyn_cast<CXXStdInitializerListExpr>(Arg))
- Arg = StdInit->getSubExpr()->IgnoreImplicit();
+ if (const auto *StdInit = dyn_cast<CXXStdInitializerListExpr>(Arg))
+ Arg = StdInit->getSubExpr()->IgnoreUnlessSpelledInSource();
if (isa<InitListExpr>(Arg))
return InitListKind::Anonymous;
@@ -236,8 +234,12 @@ static InitListKind getInitListKind(const Expr *Arg) {
return InitListKind::Anonymous;
}
+ // std::initializer_list<T>{...} is represented as a functional cast whose
+ // subexpression carries the list-initialization spelling.
if (const auto *FuncCast = dyn_cast<CXXFunctionalCastExpr>(Arg)) {
- if (FuncCast->isListInitialization())
+ const Expr *SubExpr = FuncCast->getSubExpr()->IgnoreImplicit();
+ if (FuncCast->isListInitialization() ||
+ isa<CXXStdInitializerListExpr>(SubExpr))
return InitListKind::Typed;
}
@@ -247,6 +249,8 @@ static InitListKind getInitListKind(const Expr *Arg) {
// Given the argument type and the options determine if we should
// be adding an argument comment.
bool ArgumentCommentCheck::shouldAddComment(const Expr *Arg) const {
+ const InitListKind Kind = getInitListKind(Arg);
+
// Strip implicit wrappers so brace-init arguments bound to references still
// look like list-initialization at this point.
Arg = Arg->IgnoreImplicit();
@@ -255,8 +259,6 @@ bool ArgumentCommentCheck::shouldAddComment(const Expr *Arg) const {
if (Arg->getExprLoc().isMacroID())
return false;
- const InitListKind Kind = getInitListKind(Arg);
-
return (CommentAnonymousInitLists && Kind == InitListKind::Anonymous) ||
(CommentTypedInitLists && Kind == InitListKind::Typed) ||
(CommentBoolLiterals && isa<CXXBoolLiteralExpr>(Arg)) ||
diff --git a/clang-tools-extra/test/clang-tidy/checkers/bugprone/argument-comment-init-list-cxx20.cpp b/clang-tools-extra/test/clang-tidy/checkers/bugprone/argument-comment-init-list-cxx20.cpp
index bcb1f7c68cd74..d4e1abb69ebef 100644
--- a/clang-tools-extra/test/clang-tidy/checkers/bugprone/argument-comment-init-list-cxx20.cpp
+++ b/clang-tools-extra/test/clang-tidy/checkers/bugprone/argument-comment-init-list-cxx20.cpp
@@ -10,8 +10,6 @@
// RUN: bugprone-argument-comment.CommentAnonymousInitLists: true, \
// RUN: bugprone-argument-comment.CommentTypedInitLists: true}}" --
-namespace GH171842 {
-
struct T {
int value;
};
@@ -44,5 +42,3 @@ void test_designated_init() {
// CHECK-MESSAGES-BOTH: [[@LINE-5]]:28: warning: argument comment missing for literal argument 'dims' [bugprone-argument-comment]
// CHECK-FIXES-BOTH: foo_designated(some_arg, /*dims=*/Agg{.x = 1});
}
-
-} // namespace GH171842
diff --git a/clang-tools-extra/test/clang-tidy/checkers/bugprone/argument-comment-init-list.cpp b/clang-tools-extra/test/clang-tidy/checkers/bugprone/argument-comment-init-list.cpp
index a3238a5cb4871..bc3d2736858e0 100644
--- a/clang-tools-extra/test/clang-tidy/checkers/bugprone/argument-comment-init-list.cpp
+++ b/clang-tools-extra/test/clang-tidy/checkers/bugprone/argument-comment-init-list.cpp
@@ -13,16 +13,18 @@
#include <initializer_list>
#include <vector>
-namespace GH171842 {
-
struct T {
int value;
};
void foo(T some_arg, const std::vector<int> &dims);
void foo_init_list(T some_arg, std::initializer_list<int> dims);
+void foo_nested_init_list(T some_arg,
+ std::initializer_list<std::initializer_list<int>> dims);
template <typename ElemTy>
void foo_template(T some_arg, const std::vector<ElemTy> &dims);
+template <typename DimsTy>
+void foo_template_typed(T some_arg, const DimsTy &dims);
void test_braced_init_list() {
T some_arg{0};
@@ -76,6 +78,26 @@ void test_initializer_list() {
// CHECK-MESSAGES-TYPED-NOT: :[[@LINE-4]]:27: warning: argument comment missing for literal argument 'dims'
// CHECK-MESSAGES-BOTH: [[@LINE-5]]:27: warning: argument comment missing for literal argument 'dims' [bugprone-argument-comment]
// CHECK-FIXES-BOTH: foo_init_list(some_arg, /*dims=*/{1, 2, 3});
+
+ foo_init_list(some_arg, std::initializer_list<int>{1, 2, 3});
+ // CHECK-MESSAGES-OFF-NOT: :[[@LINE-1]]:27: warning: argument comment missing for literal argument 'dims'
+ // CHECK-MESSAGES-ANON-NOT: :[[@LINE-2]]:27: warning: argument comment missing for literal argument 'dims'
+ // CHECK-MESSAGES-TYPED: [[@LINE-3]]:27: warning: argument comment missing for literal argument 'dims' [bugprone-argument-comment]
+ // CHECK-FIXES-TYPED: foo_init_list(some_arg, /*dims=*/std::initializer_list<int>{1, 2, 3});
+ // CHECK-MESSAGES-BOTH: [[@LINE-5]]:27: warning: argument comment missing for literal argument 'dims' [bugprone-argument-comment]
+ // CHECK-FIXES-BOTH: foo_init_list(some_arg, /*dims=*/std::initializer_list<int>{1, 2, 3});
+}
+
+void test_nested_initializer_list() {
+ T some_arg{0};
+
+ foo_nested_init_list(some_arg, {{1, 2}, {3, 4}});
+ // CHECK-MESSAGES-OFF-NOT: :[[@LINE-1]]:34: warning: argument comment missing for literal argument 'dims'
+ // CHECK-MESSAGES-ANON: [[@LINE-2]]:34: warning: argument comment missing for literal argument 'dims' [bugprone-argument-comment]
+ // CHECK-FIXES-ANON: foo_nested_init_list(some_arg, /*dims=*/{{.*}});
+ // CHECK-MESSAGES-TYPED-NOT: :[[@LINE-4]]:34: warning: argument comment missing for literal argument 'dims'
+ // CHECK-MESSAGES-BOTH: [[@LINE-5]]:34: warning: argument comment missing for literal argument 'dims' [bugprone-argument-comment]
+ // CHECK-FIXES-BOTH: foo_nested_init_list(some_arg, /*dims=*/{{.*}});
}
template <typename ElemTy>
@@ -99,6 +121,18 @@ void test_template_dependent_init_list() {
// CHECK-FIXES-BOTH: foo_template<ElemTy>(some_arg, /*dims=*/std::vector<ElemTy>{});
}
-template void test_template_dependent_init_list<int>();
+template <typename DimsTy>
+void test_template_dependent_typed_init_list() {
+ T some_arg{0};
+
+ foo_template_typed<DimsTy>(some_arg, DimsTy{1, 2, 3});
+ // CHECK-MESSAGES-OFF-NOT: :[[@LINE-1]]:40: warning: argument comment missing for literal argument 'dims'
+ // CHECK-MESSAGES-ANON-NOT: :[[@LINE-2]]:40: warning: argument comment missing for literal argument 'dims'
+ // CHECK-MESSAGES-TYPED: [[@LINE-3]]:40: warning: argument comment missing for literal argument 'dims' [bugprone-argument-comment]
+ // CHECK-FIXES-TYPED: foo_template_typed<DimsTy>(some_arg, /*dims=*/DimsTy{1, 2, 3});
+ // CHECK-MESSAGES-BOTH: [[@LINE-5]]:40: warning: argument comment missing for literal argument 'dims' [bugprone-argument-comment]
+ // CHECK-FIXES-BOTH: foo_template_typed<DimsTy>(some_arg, /*dims=*/DimsTy{1, 2, 3});
+}
-} // namespace GH171842
+template void test_template_dependent_init_list<int>();
+template void test_template_dependent_typed_init_list<std::vector<int>>();
diff --git a/clang-tools-extra/test/clang-tidy/checkers/bugprone/argument-comment-literals.cpp b/clang-tools-extra/test/clang-tidy/checkers/bugprone/argument-comment-literals.cpp
index 41283f66a2f26..f03488a14d9f5 100644
--- a/clang-tools-extra/test/clang-tidy/checkers/bugprone/argument-comment-literals.cpp
+++ b/clang-tools-extra/test/clang-tidy/checkers/bugprone/argument-comment-literals.cpp
@@ -7,6 +7,7 @@
// RUN: bugprone-argument-comment.CommentStringLiterals: true, \
// RUN: bugprone-argument-comment.CommentNullPtrs: true, \
// RUN: bugprone-argument-comment.CommentCharacterLiterals: true}}" --
+
struct A {
void foo(bool abc);
void foo(bool abc, bool cde);
>From 648fff9e9d9b3f9ff6afc832c1c28de955415713 Mon Sep 17 00:00:00 2001
From: Daniil Dudkin <unterumarmung at yandex.ru>
Date: Sun, 29 Mar 2026 23:44:55 +0300
Subject: [PATCH 3/3] fix review comments
---
.../bugprone/ArgumentCommentCheck.cpp | 92 ++++++----
.../bugprone/ArgumentCommentCheck.h | 25 ++-
clang-tools-extra/docs/ReleaseNotes.rst | 7 +-
.../checks/bugprone/argument-comment.rst | 142 +++++++++------
.../argument-comment-init-list-cxx20.cpp | 23 ++-
.../bugprone/argument-comment-init-list.cpp | 167 ++++++++++++++----
6 files changed, 324 insertions(+), 132 deletions(-)
diff --git a/clang-tools-extra/clang-tidy/bugprone/ArgumentCommentCheck.cpp b/clang-tools-extra/clang-tidy/bugprone/ArgumentCommentCheck.cpp
index 94190999984af..f54e85e1fa8dd 100644
--- a/clang-tools-extra/clang-tidy/bugprone/ArgumentCommentCheck.cpp
+++ b/clang-tools-extra/clang-tidy/bugprone/ArgumentCommentCheck.cpp
@@ -36,31 +36,35 @@ ArgumentCommentCheck::ArgumentCommentCheck(StringRef Name,
: ClangTidyCheck(Name, Context),
StrictMode(Options.get("StrictMode", false)),
IgnoreSingleArgument(Options.get("IgnoreSingleArgument", false)),
+ CommentAnonymousInitLists(
+ Options.get("CommentAnonymousInitLists", false)),
CommentBoolLiterals(Options.get("CommentBoolLiterals", false)),
- CommentIntegerLiterals(Options.get("CommentIntegerLiterals", false)),
+ CommentCharacterLiterals(Options.get("CommentCharacterLiterals", false)),
CommentFloatLiterals(Options.get("CommentFloatLiterals", false)),
+ CommentIntegerLiterals(Options.get("CommentIntegerLiterals", false)),
+ CommentNullPtrs(Options.get("CommentNullPtrs", false)),
+ CommentParenthesizedTemporaries(
+ Options.get("CommentParenthesizedTemporaries", false)),
CommentStringLiterals(Options.get("CommentStringLiterals", false)),
+ CommentTypedInitLists(Options.get("CommentTypedInitLists", false)),
CommentUserDefinedLiterals(
Options.get("CommentUserDefinedLiterals", false)),
- CommentCharacterLiterals(Options.get("CommentCharacterLiterals", false)),
- CommentAnonymousInitLists(
- Options.get("CommentAnonymousInitLists", false)),
- CommentTypedInitLists(Options.get("CommentTypedInitLists", false)),
- CommentNullPtrs(Options.get("CommentNullPtrs", false)),
IdentRE("^(/\\* *)([_A-Za-z][_A-Za-z0-9]*)( *= *\\*/)$") {}
void ArgumentCommentCheck::storeOptions(ClangTidyOptions::OptionMap &Opts) {
Options.store(Opts, "StrictMode", StrictMode);
Options.store(Opts, "IgnoreSingleArgument", IgnoreSingleArgument);
+ Options.store(Opts, "CommentAnonymousInitLists", CommentAnonymousInitLists);
Options.store(Opts, "CommentBoolLiterals", CommentBoolLiterals);
- Options.store(Opts, "CommentIntegerLiterals", CommentIntegerLiterals);
+ Options.store(Opts, "CommentCharacterLiterals", CommentCharacterLiterals);
Options.store(Opts, "CommentFloatLiterals", CommentFloatLiterals);
+ Options.store(Opts, "CommentIntegerLiterals", CommentIntegerLiterals);
+ Options.store(Opts, "CommentNullPtrs", CommentNullPtrs);
+ Options.store(Opts, "CommentParenthesizedTemporaries",
+ CommentParenthesizedTemporaries);
Options.store(Opts, "CommentStringLiterals", CommentStringLiterals);
- Options.store(Opts, "CommentUserDefinedLiterals", CommentUserDefinedLiterals);
- Options.store(Opts, "CommentCharacterLiterals", CommentCharacterLiterals);
- Options.store(Opts, "CommentAnonymousInitLists", CommentAnonymousInitLists);
Options.store(Opts, "CommentTypedInitLists", CommentTypedInitLists);
- Options.store(Opts, "CommentNullPtrs", CommentNullPtrs);
+ Options.store(Opts, "CommentUserDefinedLiterals", CommentUserDefinedLiterals);
}
void ArgumentCommentCheck::registerMatchers(MatchFinder *Finder) {
@@ -246,10 +250,19 @@ static InitListKind getInitListKind(const Expr *Arg) {
return InitListKind::None;
}
-// Given the argument type and the options determine if we should
-// be adding an argument comment.
-bool ArgumentCommentCheck::shouldAddComment(const Expr *Arg) const {
+static bool isParenthesizedTemporary(const Expr *Arg) {
+ Arg = Arg->IgnoreUnlessSpelledInSource();
+ if (const auto *TempObject = dyn_cast<CXXTemporaryObjectExpr>(Arg))
+ return !TempObject->isListInitialization();
+ return false;
+}
+
+// Given the argument type and the options determine if we should be adding an
+// argument comment and which diagnostic wording to use.
+ArgumentCommentCheck::CommentKind
+ArgumentCommentCheck::shouldAddComment(const Expr *Arg) const {
const InitListKind Kind = getInitListKind(Arg);
+ const bool IsParenthesizedTemporary = isParenthesizedTemporary(Arg);
// Strip implicit wrappers so brace-init arguments bound to references still
// look like list-initialization at this point.
@@ -257,17 +270,25 @@ bool ArgumentCommentCheck::shouldAddComment(const Expr *Arg) const {
if (const auto *UO = dyn_cast<UnaryOperator>(Arg))
Arg = UO->getSubExpr()->IgnoreImplicit();
if (Arg->getExprLoc().isMacroID())
- return false;
+ return CommentKind::None;
+
+ if ((CommentAnonymousInitLists && Kind == InitListKind::Anonymous) ||
+ (CommentTypedInitLists && Kind == InitListKind::Typed) ||
+ (CommentParenthesizedTemporaries && IsParenthesizedTemporary)) {
+ return CommentKind::NonLiteral;
+ }
+
+ if ((CommentBoolLiterals && isa<CXXBoolLiteralExpr>(Arg)) ||
+ (CommentIntegerLiterals && isa<IntegerLiteral>(Arg)) ||
+ (CommentFloatLiterals && isa<FloatingLiteral>(Arg)) ||
+ (CommentUserDefinedLiterals && isa<UserDefinedLiteral>(Arg)) ||
+ (CommentCharacterLiterals && isa<CharacterLiteral>(Arg)) ||
+ (CommentStringLiterals && isa<StringLiteral>(Arg)) ||
+ (CommentNullPtrs && isa<CXXNullPtrLiteralExpr>(Arg))) {
+ return CommentKind::Literal;
+ }
- return (CommentAnonymousInitLists && Kind == InitListKind::Anonymous) ||
- (CommentTypedInitLists && Kind == InitListKind::Typed) ||
- (CommentBoolLiterals && isa<CXXBoolLiteralExpr>(Arg)) ||
- (CommentIntegerLiterals && isa<IntegerLiteral>(Arg)) ||
- (CommentFloatLiterals && isa<FloatingLiteral>(Arg)) ||
- (CommentUserDefinedLiterals && isa<UserDefinedLiteral>(Arg)) ||
- (CommentCharacterLiterals && isa<CharacterLiteral>(Arg)) ||
- (CommentStringLiterals && isa<StringLiteral>(Arg)) ||
- (CommentNullPtrs && isa<CXXNullPtrLiteralExpr>(Arg));
+ return CommentKind::None;
}
void ArgumentCommentCheck::checkCallArgs(ASTContext *Ctx,
@@ -336,8 +357,11 @@ void ArgumentCommentCheck::checkCallArgs(ASTContext *Ctx,
"match parameter name %1")
<< Matches[2] << II;
if (isLikelyTypo(Callee->parameters(), Matches[2], II->getName())) {
- Diag << FixItHint::CreateReplacement(
- Comment.Loc, (Matches[1] + II->getName() + Matches[3]).str());
+ const std::string CorrectedComment = llvm::Twine(Matches[1])
+ .concat(II->getName())
+ .concat(Matches[3])
+ .str();
+ Diag << FixItHint::CreateReplacement(Comment.Loc, CorrectedComment);
}
}
diag(PVD->getLocation(), "%0 declared here", DiagnosticIDs::Note) << II;
@@ -349,14 +373,20 @@ void ArgumentCommentCheck::checkCallArgs(ASTContext *Ctx,
}
}
- // If the argument comments are missing for literals add them.
- if (Comments.empty() && shouldAddComment(Args[I])) {
+ // If the argument comments are missing for configured argument kinds, add
+ // them.
+ const CommentKind Kind = shouldAddComment(Args[I]);
+ if (Comments.empty() && Kind != CommentKind::None) {
SmallString<32> ArgComment;
- (llvm::Twine("/*") + II->getName() + "=*/").toStringRef(ArgComment);
+ llvm::Twine("/*")
+ .concat(II->getName())
+ .concat("=*/")
+ .toStringRef(ArgComment);
const DiagnosticBuilder Diag =
diag(Args[I]->getBeginLoc(),
- "argument comment missing for literal argument %0")
- << II
+ "argument comment missing for %select{literal argument|"
+ "argument}0 %1")
+ << (Kind == CommentKind::Literal ? 0 : 1) << II
<< FixItHint::CreateInsertion(Args[I]->getBeginLoc(), ArgComment);
}
}
diff --git a/clang-tools-extra/clang-tidy/bugprone/ArgumentCommentCheck.h b/clang-tools-extra/clang-tidy/bugprone/ArgumentCommentCheck.h
index 60a1338233f66..3bed1ad4247e5 100644
--- a/clang-tools-extra/clang-tidy/bugprone/ArgumentCommentCheck.h
+++ b/clang-tools-extra/clang-tidy/bugprone/ArgumentCommentCheck.h
@@ -14,7 +14,8 @@
namespace clang::tidy::bugprone {
-/// Checks that argument comments match parameter names.
+/// Checks that argument comments match parameter names and can optionally add
+/// missing comments for literals, init-lists, and constructed temporaries.
///
/// The check understands argument comments in the form `/*parameter_name=*/`
/// that are placed right before the argument.
@@ -28,7 +29,8 @@ namespace clang::tidy::bugprone {
/// 'foo'
/// \endcode
///
-/// The check tries to detect typos and suggest automated fixes for them.
+/// The check tries to detect typos and suggest automated fixes for them. It can
+/// also insert missing comments for configured argument kinds.
class ArgumentCommentCheck : public ClangTidyCheck {
public:
ArgumentCommentCheck(StringRef Name, ClangTidyContext *Context);
@@ -38,24 +40,31 @@ class ArgumentCommentCheck : public ClangTidyCheck {
void storeOptions(ClangTidyOptions::OptionMap &Opts) override;
private:
+ enum class CommentKind {
+ None,
+ Literal,
+ NonLiteral,
+ };
+
const unsigned StrictMode : 1;
const unsigned IgnoreSingleArgument : 1;
+ const unsigned CommentAnonymousInitLists : 1;
const unsigned CommentBoolLiterals : 1;
- const unsigned CommentIntegerLiterals : 1;
+ const unsigned CommentCharacterLiterals : 1;
const unsigned CommentFloatLiterals : 1;
+ const unsigned CommentIntegerLiterals : 1;
+ const unsigned CommentNullPtrs : 1;
+ const unsigned CommentParenthesizedTemporaries : 1;
const unsigned CommentStringLiterals : 1;
- const unsigned CommentUserDefinedLiterals : 1;
- const unsigned CommentCharacterLiterals : 1;
- const unsigned CommentAnonymousInitLists : 1;
const unsigned CommentTypedInitLists : 1;
- const unsigned CommentNullPtrs : 1;
+ const unsigned CommentUserDefinedLiterals : 1;
llvm::Regex IdentRE;
void checkCallArgs(ASTContext *Ctx, const FunctionDecl *Callee,
SourceLocation ArgBeginLoc,
llvm::ArrayRef<const Expr *> Args);
- bool shouldAddComment(const Expr *Arg) const;
+ CommentKind shouldAddComment(const Expr *Arg) const;
};
} // namespace clang::tidy::bugprone
diff --git a/clang-tools-extra/docs/ReleaseNotes.rst b/clang-tools-extra/docs/ReleaseNotes.rst
index 216d878d05c39..674192668a013 100644
--- a/clang-tools-extra/docs/ReleaseNotes.rst
+++ b/clang-tools-extra/docs/ReleaseNotes.rst
@@ -197,9 +197,10 @@ Changes in existing checks
- Checks for C++11 inherited constructors.
- - Adds `CommentAnonymousInitLists` and `CommentTypedInitLists` options
- to comment braced-init list arguments (for example, ``{}`` and
- ``Type{}``).
+ - Adds `CommentAnonymousInitLists`, `CommentTypedInitLists`, and
+ `CommentParenthesizedTemporaries` options to comment braced-init list
+ arguments and explicit temporary constructions (for example, ``{}``,
+ ``Type{}``, and ``Type()``).
- Improved :doc:`bugprone-bad-signal-to-kill-thread
<clang-tidy/checks/bugprone/bad-signal-to-kill-thread>` check by fixing false
diff --git a/clang-tools-extra/docs/clang-tidy/checks/bugprone/argument-comment.rst b/clang-tools-extra/docs/clang-tidy/checks/bugprone/argument-comment.rst
index dc028cde2fcc4..a5863ab32c41f 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/bugprone/argument-comment.rst
+++ b/clang-tools-extra/docs/clang-tidy/checks/bugprone/argument-comment.rst
@@ -3,7 +3,8 @@
bugprone-argument-comment
=========================
-Checks that argument comments match parameter names.
+Checks that argument comments match parameter names and can optionally add
+missing comments for literals, init-lists, and constructed temporaries.
The check understands argument comments in the form ``/*parameter_name=*/``
that are placed right before the argument.
@@ -17,7 +18,8 @@ that are placed right before the argument.
f(/*bar=*/true);
// warning: argument name 'bar' in comment does not match parameter name 'foo'
-The check tries to detect typos and suggest automated fixes for them.
+The check tries to detect typos and suggest automated fixes for them. It can
+also insert missing comments for configured argument kinds.
Options
-------
@@ -32,6 +34,28 @@ Options
When `true`, the check will ignore the single argument. Default is `false`.
+.. option:: CommentAnonymousInitLists
+
+ When `true`, the check will add argument comments in the format
+ ``/*ParameterName=*/`` right before anonymous braced-init list arguments
+ such as ``{}`` and ``{1, 2, 3}``. Default is `false`.
+
+Before:
+
+.. code-block:: c++
+
+ void foo(const std::vector<int> &Dims);
+
+ foo({});
+
+After:
+
+.. code-block:: c++
+
+ void foo(const std::vector<int> &Dims);
+
+ foo(/*Dims=*/{});
+
.. option:: CommentBoolLiterals
When `true`, the check will add argument comments in the format
@@ -54,27 +78,27 @@ After:
foo(/*TurnKey=*/true, /*PressButton=*/false);
-.. option:: CommentIntegerLiterals
+.. option:: CommentCharacterLiterals
When `true`, the check will add argument comments in the format
- ``/*ParameterName=*/`` right before the integer literal argument.
+ ``/*ParameterName=*/`` right before the character literal argument.
Default is `false`.
Before:
.. code-block:: c++
- void foo(int MeaningOfLife);
+ void foo(char *Character);
- foo(42);
+ foo('A');
After:
.. code-block:: c++
- void foo(int MeaningOfLife);
+ void foo(char *Character);
- foo(/*MeaningOfLife=*/42);
+ foo(/*Character=*/'A');
.. option:: CommentFloatLiterals
@@ -98,75 +122,109 @@ After:
foo(/*Pi=*/3.14159);
-.. option:: CommentStringLiterals
+.. option:: CommentIntegerLiterals
When `true`, the check will add argument comments in the format
- ``/*ParameterName=*/`` right before the string literal argument.
+ ``/*ParameterName=*/`` right before the integer literal argument.
Default is `false`.
Before:
.. code-block:: c++
- void foo(const char *String);
- void foo(const wchar_t *WideString);
+ void foo(int MeaningOfLife);
- foo("Hello World");
- foo(L"Hello World");
+ foo(42);
After:
.. code-block:: c++
- void foo(const char *String);
- void foo(const wchar_t *WideString);
+ void foo(int MeaningOfLife);
- foo(/*String=*/"Hello World");
- foo(/*WideString=*/L"Hello World");
+ foo(/*MeaningOfLife=*/42);
-.. option:: CommentCharacterLiterals
+.. option:: CommentNullPtrs
When `true`, the check will add argument comments in the format
- ``/*ParameterName=*/`` right before the character literal argument.
+ ``/*ParameterName=*/`` right before the nullptr literal argument.
Default is `false`.
Before:
.. code-block:: c++
- void foo(char *Character);
+ void foo(A* Value);
- foo('A');
+ foo(nullptr);
After:
.. code-block:: c++
- void foo(char *Character);
+ void foo(A* Value);
- foo(/*Character=*/'A');
+ foo(/*Value=*/nullptr);
-.. option:: CommentAnonymousInitLists
+.. option:: CommentParenthesizedTemporaries
When `true`, the check will add argument comments in the format
- ``/*ParameterName=*/`` right before anonymous braced-init list arguments
- such as ``{}`` and ``{1, 2, 3}``. Default is `false`.
+ ``/*ParameterName=*/`` right before explicit temporary constructions such as
+ ``Type()`` and ``Type(1, 2, 3)``. Default is `false`.
Before:
.. code-block:: c++
- void foo(const std::vector<int> &Dims);
+ struct Dims {
+ Dims();
+ Dims(int, int, int);
+ };
- foo({});
+ void foo(const Dims &DimsValue);
+
+ foo(Dims());
+ foo(Dims(1, 2, 3));
After:
.. code-block:: c++
- void foo(const std::vector<int> &Dims);
+ struct Dims {
+ Dims();
+ Dims(int, int, int);
+ };
- foo(/*Dims=*/{});
+ void foo(const Dims &DimsValue);
+
+ foo(/*DimsValue=*/Dims());
+ foo(/*DimsValue=*/Dims(1, 2, 3));
+
+.. option:: CommentStringLiterals
+
+ When `true`, the check will add argument comments in the format
+ ``/*ParameterName=*/`` right before the string literal argument.
+ Default is `false`.
+
+Before:
+
+.. code-block:: c++
+
+ void foo(const char *String);
+ void foo(const wchar_t *WideString);
+
+ foo("Hello World");
+ foo(L"Hello World");
+
+After:
+
+.. code-block:: c++
+
+ void foo(const char *String);
+ void foo(const wchar_t *WideString);
+
+ foo(/*String=*/"Hello World");
+ foo(/*WideString=*/L"Hello World");
.. option:: CommentTypedInitLists
@@ -215,25 +273,3 @@ After:
double operator"" _km(long double);
foo(/*Distance=*/402.0_km);
-
-.. option:: CommentNullPtrs
-
- When `true`, the check will add argument comments in the format
- ``/*ParameterName=*/`` right before the nullptr literal argument.
- Default is `false`.
-
-Before:
-
-.. code-block:: c++
-
- void foo(A* Value);
-
- foo(nullptr);
-
-After:
-
-.. code-block:: c++
-
- void foo(A* Value);
-
- foo(/*Value=*/nullptr);
diff --git a/clang-tools-extra/test/clang-tidy/checkers/bugprone/argument-comment-init-list-cxx20.cpp b/clang-tools-extra/test/clang-tidy/checkers/bugprone/argument-comment-init-list-cxx20.cpp
index d4e1abb69ebef..20db77862b878 100644
--- a/clang-tools-extra/test/clang-tidy/checkers/bugprone/argument-comment-init-list-cxx20.cpp
+++ b/clang-tools-extra/test/clang-tidy/checkers/bugprone/argument-comment-init-list-cxx20.cpp
@@ -5,10 +5,18 @@
// RUN: %check_clang_tidy -check-suffix=TYPED -std=c++20-or-later %s bugprone-argument-comment %t -- \
// RUN: -config="{CheckOptions: { \
// RUN: bugprone-argument-comment.CommentTypedInitLists: true}}" --
+// RUN: %check_clang_tidy -check-suffix=TEMP -std=c++20-or-later %s bugprone-argument-comment %t -- \
+// RUN: -config="{CheckOptions: { \
+// RUN: bugprone-argument-comment.CommentParenthesizedTemporaries: true}}" --
// RUN: %check_clang_tidy -check-suffix=BOTH -std=c++20-or-later %s bugprone-argument-comment %t -- \
// RUN: -config="{CheckOptions: { \
// RUN: bugprone-argument-comment.CommentAnonymousInitLists: true, \
// RUN: bugprone-argument-comment.CommentTypedInitLists: true}}" --
+// RUN: %check_clang_tidy -check-suffix=ALL -std=c++20-or-later %s bugprone-argument-comment %t -- \
+// RUN: -config="{CheckOptions: { \
+// RUN: bugprone-argument-comment.CommentAnonymousInitLists: true, \
+// RUN: bugprone-argument-comment.CommentTypedInitLists: true, \
+// RUN: bugprone-argument-comment.CommentParenthesizedTemporaries: true}}" --
struct T {
int value;
@@ -31,14 +39,21 @@ void test_designated_init() {
// CHECK-FIXES-ANON: foo_designated(some_arg, /*dims=*/Agg{.x = 1});
// CHECK-MESSAGES-TYPED: warning: argument name 'dim' in comment does not match parameter name 'dims'
// CHECK-FIXES-TYPED: foo_designated(some_arg, /*dims=*/Agg{.x = 1});
+ // CHECK-MESSAGES-TEMP: warning: argument name 'dim' in comment does not match parameter name 'dims'
+ // CHECK-FIXES-TEMP: foo_designated(some_arg, /*dims=*/Agg{.x = 1});
// CHECK-MESSAGES-BOTH: warning: argument name 'dim' in comment does not match parameter name 'dims'
// CHECK-FIXES-BOTH: foo_designated(some_arg, /*dims=*/Agg{.x = 1});
+ // CHECK-MESSAGES-ALL: warning: argument name 'dim' in comment does not match parameter name 'dims'
+ // CHECK-FIXES-ALL: foo_designated(some_arg, /*dims=*/Agg{.x = 1});
foo_designated(some_arg, Agg{.x = 1});
- // CHECK-MESSAGES-OFF-NOT: :[[@LINE-1]]:28: warning: argument comment missing for literal argument 'dims'
- // CHECK-MESSAGES-ANON-NOT: :[[@LINE-2]]:28: warning: argument comment missing for literal argument 'dims'
- // CHECK-MESSAGES-TYPED: [[@LINE-3]]:28: warning: argument comment missing for literal argument 'dims' [bugprone-argument-comment]
+ // CHECK-MESSAGES-OFF-NOT: :[[@LINE-1]]:28: warning: argument comment missing for argument 'dims'
+ // CHECK-MESSAGES-ANON-NOT: :[[@LINE-2]]:28: warning: argument comment missing for argument 'dims'
+ // CHECK-MESSAGES-TYPED: [[@LINE-3]]:28: warning: argument comment missing for argument 'dims' [bugprone-argument-comment]
// CHECK-FIXES-TYPED: foo_designated(some_arg, /*dims=*/Agg{.x = 1});
- // CHECK-MESSAGES-BOTH: [[@LINE-5]]:28: warning: argument comment missing for literal argument 'dims' [bugprone-argument-comment]
+ // CHECK-MESSAGES-TEMP-NOT: :[[@LINE-5]]:28: warning: argument comment missing for argument 'dims'
+ // CHECK-MESSAGES-BOTH: [[@LINE-6]]:28: warning: argument comment missing for argument 'dims' [bugprone-argument-comment]
// CHECK-FIXES-BOTH: foo_designated(some_arg, /*dims=*/Agg{.x = 1});
+ // CHECK-MESSAGES-ALL: [[@LINE-8]]:28: warning: argument comment missing for argument 'dims' [bugprone-argument-comment]
+ // CHECK-FIXES-ALL: foo_designated(some_arg, /*dims=*/Agg{.x = 1});
}
diff --git a/clang-tools-extra/test/clang-tidy/checkers/bugprone/argument-comment-init-list.cpp b/clang-tools-extra/test/clang-tidy/checkers/bugprone/argument-comment-init-list.cpp
index bc3d2736858e0..24a0284073b89 100644
--- a/clang-tools-extra/test/clang-tidy/checkers/bugprone/argument-comment-init-list.cpp
+++ b/clang-tools-extra/test/clang-tidy/checkers/bugprone/argument-comment-init-list.cpp
@@ -5,10 +5,18 @@
// RUN: %check_clang_tidy -check-suffix=TYPED %s bugprone-argument-comment %t -- \
// RUN: -config="{CheckOptions: { \
// RUN: bugprone-argument-comment.CommentTypedInitLists: true}}" --
+// RUN: %check_clang_tidy -check-suffix=TEMP %s bugprone-argument-comment %t -- \
+// RUN: -config="{CheckOptions: { \
+// RUN: bugprone-argument-comment.CommentParenthesizedTemporaries: true}}" --
// RUN: %check_clang_tidy -check-suffix=BOTH %s bugprone-argument-comment %t -- \
// RUN: -config="{CheckOptions: { \
// RUN: bugprone-argument-comment.CommentAnonymousInitLists: true, \
// RUN: bugprone-argument-comment.CommentTypedInitLists: true}}" --
+// RUN: %check_clang_tidy -check-suffix=ALL %s bugprone-argument-comment %t -- \
+// RUN: -config="{CheckOptions: { \
+// RUN: bugprone-argument-comment.CommentAnonymousInitLists: true, \
+// RUN: bugprone-argument-comment.CommentTypedInitLists: true, \
+// RUN: bugprone-argument-comment.CommentParenthesizedTemporaries: true}}" --
#include <initializer_list>
#include <vector>
@@ -17,10 +25,17 @@ struct T {
int value;
};
+struct Dims {
+ Dims();
+ Dims(int, int, int);
+};
+
void foo(T some_arg, const std::vector<int> &dims);
+void foo_dims(T some_arg, const Dims &dims);
void foo_init_list(T some_arg, std::initializer_list<int> dims);
void foo_nested_init_list(T some_arg,
std::initializer_list<std::initializer_list<int>> dims);
+void foo_int(T some_arg, int value);
template <typename ElemTy>
void foo_template(T some_arg, const std::vector<ElemTy> &dims);
template <typename DimsTy>
@@ -30,7 +45,7 @@ void test_braced_init_list() {
T some_arg{0};
// Mismatched explicit argument comments are validated independently of the
- // init-list literal comment options.
+ // missing-comment options.
foo(some_arg, /*dim=*/{});
// CHECK-MESSAGES-OFF: warning: argument name 'dim' in comment does not match parameter name 'dims'
// CHECK-FIXES-OFF: foo(some_arg, /*dims=*/{});
@@ -38,8 +53,12 @@ void test_braced_init_list() {
// CHECK-FIXES-ANON: foo(some_arg, /*dims=*/{});
// CHECK-MESSAGES-TYPED: warning: argument name 'dim' in comment does not match parameter name 'dims'
// CHECK-FIXES-TYPED: foo(some_arg, /*dims=*/{});
+ // CHECK-MESSAGES-TEMP: warning: argument name 'dim' in comment does not match parameter name 'dims'
+ // CHECK-FIXES-TEMP: foo(some_arg, /*dims=*/{});
// CHECK-MESSAGES-BOTH: warning: argument name 'dim' in comment does not match parameter name 'dims'
// CHECK-FIXES-BOTH: foo(some_arg, /*dims=*/{});
+ // CHECK-MESSAGES-ALL: warning: argument name 'dim' in comment does not match parameter name 'dims'
+ // CHECK-FIXES-ALL: foo(some_arg, /*dims=*/{});
foo(some_arg, /*dim=*/std::vector<int>{});
// CHECK-MESSAGES-OFF: warning: argument name 'dim' in comment does not match parameter name 'dims'
@@ -48,56 +67,129 @@ void test_braced_init_list() {
// CHECK-FIXES-ANON: foo(some_arg, /*dims=*/std::vector<int>{});
// CHECK-MESSAGES-TYPED: warning: argument name 'dim' in comment does not match parameter name 'dims'
// CHECK-FIXES-TYPED: foo(some_arg, /*dims=*/std::vector<int>{});
+ // CHECK-MESSAGES-TEMP: warning: argument name 'dim' in comment does not match parameter name 'dims'
+ // CHECK-FIXES-TEMP: foo(some_arg, /*dims=*/std::vector<int>{});
// CHECK-MESSAGES-BOTH: warning: argument name 'dim' in comment does not match parameter name 'dims'
// CHECK-FIXES-BOTH: foo(some_arg, /*dims=*/std::vector<int>{});
+ // CHECK-MESSAGES-ALL: warning: argument name 'dim' in comment does not match parameter name 'dims'
+ // CHECK-FIXES-ALL: foo(some_arg, /*dims=*/std::vector<int>{});
foo(some_arg, {});
- // CHECK-MESSAGES-OFF-NOT: :[[@LINE-1]]:17: warning: argument comment missing for literal argument 'dims'
- // CHECK-MESSAGES-ANON: [[@LINE-2]]:17: warning: argument comment missing for literal argument 'dims' [bugprone-argument-comment]
+ // CHECK-MESSAGES-OFF-NOT: :[[@LINE-1]]:17: warning: argument comment missing for argument 'dims'
+ // CHECK-MESSAGES-ANON: [[@LINE-2]]:17: warning: argument comment missing for argument 'dims' [bugprone-argument-comment]
// CHECK-FIXES-ANON: foo(some_arg, /*dims=*/{});
- // CHECK-MESSAGES-TYPED-NOT: :[[@LINE-4]]:17: warning: argument comment missing for literal argument 'dims'
- // CHECK-MESSAGES-BOTH: [[@LINE-5]]:17: warning: argument comment missing for literal argument 'dims' [bugprone-argument-comment]
+ // CHECK-MESSAGES-TYPED-NOT: :[[@LINE-4]]:17: warning: argument comment missing for argument 'dims'
+ // CHECK-MESSAGES-TEMP-NOT: :[[@LINE-5]]:17: warning: argument comment missing for argument 'dims'
+ // CHECK-MESSAGES-BOTH: [[@LINE-6]]:17: warning: argument comment missing for argument 'dims' [bugprone-argument-comment]
// CHECK-FIXES-BOTH: foo(some_arg, /*dims=*/{});
+ // CHECK-MESSAGES-ALL: [[@LINE-8]]:17: warning: argument comment missing for argument 'dims' [bugprone-argument-comment]
+ // CHECK-FIXES-ALL: foo(some_arg, /*dims=*/{});
foo(some_arg, std::vector<int>{});
- // CHECK-MESSAGES-OFF-NOT: :[[@LINE-1]]:17: warning: argument comment missing for literal argument 'dims'
- // CHECK-MESSAGES-ANON-NOT: :[[@LINE-2]]:17: warning: argument comment missing for literal argument 'dims'
- // CHECK-MESSAGES-TYPED: [[@LINE-3]]:17: warning: argument comment missing for literal argument 'dims' [bugprone-argument-comment]
+ // CHECK-MESSAGES-OFF-NOT: :[[@LINE-1]]:17: warning: argument comment missing for argument 'dims'
+ // CHECK-MESSAGES-ANON-NOT: :[[@LINE-2]]:17: warning: argument comment missing for argument 'dims'
+ // CHECK-MESSAGES-TYPED: [[@LINE-3]]:17: warning: argument comment missing for argument 'dims' [bugprone-argument-comment]
// CHECK-FIXES-TYPED: foo(some_arg, /*dims=*/std::vector<int>{});
- // CHECK-MESSAGES-BOTH: [[@LINE-5]]:17: warning: argument comment missing for literal argument 'dims' [bugprone-argument-comment]
+ // CHECK-MESSAGES-TEMP-NOT: :[[@LINE-5]]:17: warning: argument comment missing for argument 'dims'
+ // CHECK-MESSAGES-BOTH: [[@LINE-6]]:17: warning: argument comment missing for argument 'dims' [bugprone-argument-comment]
// CHECK-FIXES-BOTH: foo(some_arg, /*dims=*/std::vector<int>{});
+ // CHECK-MESSAGES-ALL: [[@LINE-8]]:17: warning: argument comment missing for argument 'dims' [bugprone-argument-comment]
+ // CHECK-FIXES-ALL: foo(some_arg, /*dims=*/std::vector<int>{});
}
void test_initializer_list() {
T some_arg{0};
foo_init_list(some_arg, {1, 2, 3});
- // CHECK-MESSAGES-OFF-NOT: :[[@LINE-1]]:27: warning: argument comment missing for literal argument 'dims'
- // CHECK-MESSAGES-ANON: [[@LINE-2]]:27: warning: argument comment missing for literal argument 'dims' [bugprone-argument-comment]
+ // CHECK-MESSAGES-OFF-NOT: :[[@LINE-1]]:27: warning: argument comment missing for argument 'dims'
+ // CHECK-MESSAGES-ANON: [[@LINE-2]]:27: warning: argument comment missing for argument 'dims' [bugprone-argument-comment]
// CHECK-FIXES-ANON: foo_init_list(some_arg, /*dims=*/{1, 2, 3});
- // CHECK-MESSAGES-TYPED-NOT: :[[@LINE-4]]:27: warning: argument comment missing for literal argument 'dims'
- // CHECK-MESSAGES-BOTH: [[@LINE-5]]:27: warning: argument comment missing for literal argument 'dims' [bugprone-argument-comment]
+ // CHECK-MESSAGES-TYPED-NOT: :[[@LINE-4]]:27: warning: argument comment missing for argument 'dims'
+ // CHECK-MESSAGES-TEMP-NOT: :[[@LINE-5]]:27: warning: argument comment missing for argument 'dims'
+ // CHECK-MESSAGES-BOTH: [[@LINE-6]]:27: warning: argument comment missing for argument 'dims' [bugprone-argument-comment]
// CHECK-FIXES-BOTH: foo_init_list(some_arg, /*dims=*/{1, 2, 3});
+ // CHECK-MESSAGES-ALL: [[@LINE-8]]:27: warning: argument comment missing for argument 'dims' [bugprone-argument-comment]
+ // CHECK-FIXES-ALL: foo_init_list(some_arg, /*dims=*/{1, 2, 3});
foo_init_list(some_arg, std::initializer_list<int>{1, 2, 3});
- // CHECK-MESSAGES-OFF-NOT: :[[@LINE-1]]:27: warning: argument comment missing for literal argument 'dims'
- // CHECK-MESSAGES-ANON-NOT: :[[@LINE-2]]:27: warning: argument comment missing for literal argument 'dims'
- // CHECK-MESSAGES-TYPED: [[@LINE-3]]:27: warning: argument comment missing for literal argument 'dims' [bugprone-argument-comment]
+ // CHECK-MESSAGES-OFF-NOT: :[[@LINE-1]]:27: warning: argument comment missing for argument 'dims'
+ // CHECK-MESSAGES-ANON-NOT: :[[@LINE-2]]:27: warning: argument comment missing for argument 'dims'
+ // CHECK-MESSAGES-TYPED: [[@LINE-3]]:27: warning: argument comment missing for argument 'dims' [bugprone-argument-comment]
// CHECK-FIXES-TYPED: foo_init_list(some_arg, /*dims=*/std::initializer_list<int>{1, 2, 3});
- // CHECK-MESSAGES-BOTH: [[@LINE-5]]:27: warning: argument comment missing for literal argument 'dims' [bugprone-argument-comment]
+ // CHECK-MESSAGES-TEMP-NOT: :[[@LINE-5]]:27: warning: argument comment missing for argument 'dims'
+ // CHECK-MESSAGES-BOTH: [[@LINE-6]]:27: warning: argument comment missing for argument 'dims' [bugprone-argument-comment]
// CHECK-FIXES-BOTH: foo_init_list(some_arg, /*dims=*/std::initializer_list<int>{1, 2, 3});
+ // CHECK-MESSAGES-ALL: [[@LINE-8]]:27: warning: argument comment missing for argument 'dims' [bugprone-argument-comment]
+ // CHECK-FIXES-ALL: foo_init_list(some_arg, /*dims=*/std::initializer_list<int>{1, 2, 3});
}
void test_nested_initializer_list() {
T some_arg{0};
foo_nested_init_list(some_arg, {{1, 2}, {3, 4}});
- // CHECK-MESSAGES-OFF-NOT: :[[@LINE-1]]:34: warning: argument comment missing for literal argument 'dims'
- // CHECK-MESSAGES-ANON: [[@LINE-2]]:34: warning: argument comment missing for literal argument 'dims' [bugprone-argument-comment]
+ // CHECK-MESSAGES-OFF-NOT: :[[@LINE-1]]:34: warning: argument comment missing for argument 'dims'
+ // CHECK-MESSAGES-ANON: [[@LINE-2]]:34: warning: argument comment missing for argument 'dims' [bugprone-argument-comment]
// CHECK-FIXES-ANON: foo_nested_init_list(some_arg, /*dims=*/{{.*}});
- // CHECK-MESSAGES-TYPED-NOT: :[[@LINE-4]]:34: warning: argument comment missing for literal argument 'dims'
- // CHECK-MESSAGES-BOTH: [[@LINE-5]]:34: warning: argument comment missing for literal argument 'dims' [bugprone-argument-comment]
+ // CHECK-MESSAGES-TYPED-NOT: :[[@LINE-4]]:34: warning: argument comment missing for argument 'dims'
+ // CHECK-MESSAGES-TEMP-NOT: :[[@LINE-5]]:34: warning: argument comment missing for argument 'dims'
+ // CHECK-MESSAGES-BOTH: [[@LINE-6]]:34: warning: argument comment missing for argument 'dims' [bugprone-argument-comment]
// CHECK-FIXES-BOTH: foo_nested_init_list(some_arg, /*dims=*/{{.*}});
+ // CHECK-MESSAGES-ALL: [[@LINE-8]]:34: warning: argument comment missing for argument 'dims' [bugprone-argument-comment]
+ // CHECK-FIXES-ALL: foo_nested_init_list(some_arg, /*dims=*/{{.*}});
+}
+
+void test_parenthesized_temporary() {
+ T some_arg{0};
+
+ foo_dims(some_arg, /*dim=*/Dims());
+ // CHECK-MESSAGES-OFF: warning: argument name 'dim' in comment does not match parameter name 'dims'
+ // CHECK-FIXES-OFF: foo_dims(some_arg, /*dims=*/Dims());
+ // CHECK-MESSAGES-ANON: warning: argument name 'dim' in comment does not match parameter name 'dims'
+ // CHECK-FIXES-ANON: foo_dims(some_arg, /*dims=*/Dims());
+ // CHECK-MESSAGES-TYPED: warning: argument name 'dim' in comment does not match parameter name 'dims'
+ // CHECK-FIXES-TYPED: foo_dims(some_arg, /*dims=*/Dims());
+ // CHECK-MESSAGES-TEMP: warning: argument name 'dim' in comment does not match parameter name 'dims'
+ // CHECK-FIXES-TEMP: foo_dims(some_arg, /*dims=*/Dims());
+ // CHECK-MESSAGES-BOTH: warning: argument name 'dim' in comment does not match parameter name 'dims'
+ // CHECK-FIXES-BOTH: foo_dims(some_arg, /*dims=*/Dims());
+ // CHECK-MESSAGES-ALL: warning: argument name 'dim' in comment does not match parameter name 'dims'
+ // CHECK-FIXES-ALL: foo_dims(some_arg, /*dims=*/Dims());
+
+ foo_dims(some_arg, Dims{});
+ // CHECK-MESSAGES-OFF-NOT: :[[@LINE-1]]:22: warning: argument comment missing for argument 'dims'
+ // CHECK-MESSAGES-ANON-NOT: :[[@LINE-2]]:22: warning: argument comment missing for argument 'dims'
+ // CHECK-MESSAGES-TYPED: [[@LINE-3]]:22: warning: argument comment missing for argument 'dims' [bugprone-argument-comment]
+ // CHECK-FIXES-TYPED: foo_dims(some_arg, /*dims=*/Dims{});
+ // CHECK-MESSAGES-TEMP-NOT: :[[@LINE-5]]:22: warning: argument comment missing for argument 'dims'
+ // CHECK-MESSAGES-BOTH: [[@LINE-6]]:22: warning: argument comment missing for argument 'dims' [bugprone-argument-comment]
+ // CHECK-FIXES-BOTH: foo_dims(some_arg, /*dims=*/Dims{});
+ // CHECK-MESSAGES-ALL: [[@LINE-8]]:22: warning: argument comment missing for argument 'dims' [bugprone-argument-comment]
+ // CHECK-FIXES-ALL: foo_dims(some_arg, /*dims=*/Dims{});
+
+ foo_dims(some_arg, Dims());
+ // CHECK-MESSAGES-OFF-NOT: :[[@LINE-1]]:22: warning: argument comment missing for argument 'dims'
+ // CHECK-MESSAGES-ANON-NOT: :[[@LINE-2]]:22: warning: argument comment missing for argument 'dims'
+ // CHECK-MESSAGES-TYPED-NOT: :[[@LINE-3]]:22: warning: argument comment missing for argument 'dims'
+ // CHECK-MESSAGES-TEMP: [[@LINE-4]]:22: warning: argument comment missing for argument 'dims' [bugprone-argument-comment]
+ // CHECK-FIXES-TEMP: foo_dims(some_arg, /*dims=*/Dims());
+ // CHECK-MESSAGES-BOTH-NOT: :[[@LINE-6]]:22: warning: argument comment missing for argument 'dims'
+ // CHECK-MESSAGES-ALL: [[@LINE-7]]:22: warning: argument comment missing for argument 'dims' [bugprone-argument-comment]
+ // CHECK-FIXES-ALL: foo_dims(some_arg, /*dims=*/Dims());
+
+ foo_dims(some_arg, Dims(1, 2, 3));
+ // CHECK-MESSAGES-OFF-NOT: :[[@LINE-1]]:22: warning: argument comment missing for argument 'dims'
+ // CHECK-MESSAGES-ANON-NOT: :[[@LINE-2]]:22: warning: argument comment missing for argument 'dims'
+ // CHECK-MESSAGES-TYPED-NOT: :[[@LINE-3]]:22: warning: argument comment missing for argument 'dims'
+ // CHECK-MESSAGES-TEMP: [[@LINE-4]]:22: warning: argument comment missing for argument 'dims' [bugprone-argument-comment]
+ // CHECK-FIXES-TEMP: foo_dims(some_arg, /*dims=*/Dims(1, 2, 3));
+ // CHECK-MESSAGES-BOTH-NOT: :[[@LINE-6]]:22: warning: argument comment missing for argument 'dims'
+ // CHECK-MESSAGES-ALL: [[@LINE-7]]:22: warning: argument comment missing for argument 'dims' [bugprone-argument-comment]
+ // CHECK-FIXES-ALL: foo_dims(some_arg, /*dims=*/Dims(1, 2, 3));
+
+ foo_int(some_arg, int(1));
+ // CHECK-MESSAGES-OFF-NOT: :[[@LINE-1]]:21: warning: argument comment missing for argument 'value'
+ // CHECK-MESSAGES-TEMP-NOT: :[[@LINE-2]]:21: warning: argument comment missing for argument 'value'
+ // CHECK-MESSAGES-ALL-NOT: :[[@LINE-3]]:21: warning: argument comment missing for argument 'value'
}
template <typename ElemTy>
@@ -105,20 +197,26 @@ void test_template_dependent_init_list() {
T some_arg{0};
foo_template<ElemTy>(some_arg, {});
- // CHECK-MESSAGES-OFF-NOT: :[[@LINE-1]]:34: warning: argument comment missing for literal argument 'dims'
- // CHECK-MESSAGES-ANON: [[@LINE-2]]:34: warning: argument comment missing for literal argument 'dims' [bugprone-argument-comment]
+ // CHECK-MESSAGES-OFF-NOT: :[[@LINE-1]]:34: warning: argument comment missing for argument 'dims'
+ // CHECK-MESSAGES-ANON: [[@LINE-2]]:34: warning: argument comment missing for argument 'dims' [bugprone-argument-comment]
// CHECK-FIXES-ANON: foo_template<ElemTy>(some_arg, /*dims=*/{});
- // CHECK-MESSAGES-TYPED-NOT: :[[@LINE-4]]:34: warning: argument comment missing for literal argument 'dims'
- // CHECK-MESSAGES-BOTH: [[@LINE-5]]:34: warning: argument comment missing for literal argument 'dims' [bugprone-argument-comment]
+ // CHECK-MESSAGES-TYPED-NOT: :[[@LINE-4]]:34: warning: argument comment missing for argument 'dims'
+ // CHECK-MESSAGES-TEMP-NOT: :[[@LINE-5]]:34: warning: argument comment missing for argument 'dims'
+ // CHECK-MESSAGES-BOTH: [[@LINE-6]]:34: warning: argument comment missing for argument 'dims' [bugprone-argument-comment]
// CHECK-FIXES-BOTH: foo_template<ElemTy>(some_arg, /*dims=*/{});
+ // CHECK-MESSAGES-ALL: [[@LINE-8]]:34: warning: argument comment missing for argument 'dims' [bugprone-argument-comment]
+ // CHECK-FIXES-ALL: foo_template<ElemTy>(some_arg, /*dims=*/{});
foo_template<ElemTy>(some_arg, std::vector<ElemTy>{});
- // CHECK-MESSAGES-OFF-NOT: :[[@LINE-1]]:34: warning: argument comment missing for literal argument 'dims'
- // CHECK-MESSAGES-ANON-NOT: :[[@LINE-2]]:34: warning: argument comment missing for literal argument 'dims'
- // CHECK-MESSAGES-TYPED: [[@LINE-3]]:34: warning: argument comment missing for literal argument 'dims' [bugprone-argument-comment]
+ // CHECK-MESSAGES-OFF-NOT: :[[@LINE-1]]:34: warning: argument comment missing for argument 'dims'
+ // CHECK-MESSAGES-ANON-NOT: :[[@LINE-2]]:34: warning: argument comment missing for argument 'dims'
+ // CHECK-MESSAGES-TYPED: [[@LINE-3]]:34: warning: argument comment missing for argument 'dims' [bugprone-argument-comment]
// CHECK-FIXES-TYPED: foo_template<ElemTy>(some_arg, /*dims=*/std::vector<ElemTy>{});
- // CHECK-MESSAGES-BOTH: [[@LINE-5]]:34: warning: argument comment missing for literal argument 'dims' [bugprone-argument-comment]
+ // CHECK-MESSAGES-TEMP-NOT: :[[@LINE-5]]:34: warning: argument comment missing for argument 'dims'
+ // CHECK-MESSAGES-BOTH: [[@LINE-6]]:34: warning: argument comment missing for argument 'dims' [bugprone-argument-comment]
// CHECK-FIXES-BOTH: foo_template<ElemTy>(some_arg, /*dims=*/std::vector<ElemTy>{});
+ // CHECK-MESSAGES-ALL: [[@LINE-8]]:34: warning: argument comment missing for argument 'dims' [bugprone-argument-comment]
+ // CHECK-FIXES-ALL: foo_template<ElemTy>(some_arg, /*dims=*/std::vector<ElemTy>{});
}
template <typename DimsTy>
@@ -126,12 +224,15 @@ void test_template_dependent_typed_init_list() {
T some_arg{0};
foo_template_typed<DimsTy>(some_arg, DimsTy{1, 2, 3});
- // CHECK-MESSAGES-OFF-NOT: :[[@LINE-1]]:40: warning: argument comment missing for literal argument 'dims'
- // CHECK-MESSAGES-ANON-NOT: :[[@LINE-2]]:40: warning: argument comment missing for literal argument 'dims'
- // CHECK-MESSAGES-TYPED: [[@LINE-3]]:40: warning: argument comment missing for literal argument 'dims' [bugprone-argument-comment]
+ // CHECK-MESSAGES-OFF-NOT: :[[@LINE-1]]:40: warning: argument comment missing for argument 'dims'
+ // CHECK-MESSAGES-ANON-NOT: :[[@LINE-2]]:40: warning: argument comment missing for argument 'dims'
+ // CHECK-MESSAGES-TYPED: [[@LINE-3]]:40: warning: argument comment missing for argument 'dims' [bugprone-argument-comment]
// CHECK-FIXES-TYPED: foo_template_typed<DimsTy>(some_arg, /*dims=*/DimsTy{1, 2, 3});
- // CHECK-MESSAGES-BOTH: [[@LINE-5]]:40: warning: argument comment missing for literal argument 'dims' [bugprone-argument-comment]
+ // CHECK-MESSAGES-TEMP-NOT: :[[@LINE-5]]:40: warning: argument comment missing for argument 'dims'
+ // CHECK-MESSAGES-BOTH: [[@LINE-6]]:40: warning: argument comment missing for argument 'dims' [bugprone-argument-comment]
// CHECK-FIXES-BOTH: foo_template_typed<DimsTy>(some_arg, /*dims=*/DimsTy{1, 2, 3});
+ // CHECK-MESSAGES-ALL: [[@LINE-8]]:40: warning: argument comment missing for argument 'dims' [bugprone-argument-comment]
+ // CHECK-FIXES-ALL: foo_template_typed<DimsTy>(some_arg, /*dims=*/DimsTy{1, 2, 3});
}
template void test_template_dependent_init_list<int>();
More information about the cfe-commits
mailing list