llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-clang-tools-extra
@llvm/pr-subscribers-clang-tidy
Author: None (maflcko)
<details>
<summary>Changes</summary>
Currently, C++11 inherited constructors are not checked. For example:
```cpp
struct Base {
explicit Base(int val) {}
};
struct Over : public Base {
using Base::Base;
};
int main() {
Base b{/*wrong=*/2}; // checked
Over o{/*wrong=*/3}; // NOT checked right now
}
```
Fix this.
Godbolt: https://godbolt.org/z/88nPraK9o
---
Full diff: https://github.com/llvm/llvm-project/pull/179105.diff
3 Files Affected:
- (modified) clang-tools-extra/clang-tidy/bugprone/ArgumentCommentCheck.cpp
(+8)
- (modified) clang-tools-extra/docs/ReleaseNotes.rst (+4)
- (added)
clang-tools-extra/test/clang-tidy/checkers/bugprone/argument-comment-cxx-11-inherited-constructors.cpp
(+22)
``````````diff
diff --git a/clang-tools-extra/clang-tidy/bugprone/ArgumentCommentCheck.cpp
b/clang-tools-extra/clang-tidy/bugprone/ArgumentCommentCheck.cpp
index 2e963cd995f74..6581f49b8ef30 100644
--- a/clang-tools-extra/clang-tidy/bugprone/ArgumentCommentCheck.cpp
+++ b/clang-tools-extra/clang-tidy/bugprone/ArgumentCommentCheck.cpp
@@ -268,6 +268,14 @@ void ArgumentCommentCheck::checkCallArgs(ASTContext *Ctx,
return;
Callee = Callee->getFirstDecl();
+ if (const auto *Ctor = dyn_cast<CXXConstructorDecl>(Callee)) {
+ if (Ctor->isInheritingConstructor()) {
+ if (const auto *BaseCtor =
+ Ctor->getInheritedConstructor().getConstructor()) {
+ Callee = BaseCtor->getFirstDecl();
+ }
+ }
+ }
const unsigned NumArgs =
std::min<unsigned>(Args.size(), Callee->getNumParams());
if ((NumArgs == 0) || (IgnoreSingleArgument && NumArgs == 1))
diff --git a/clang-tools-extra/docs/ReleaseNotes.rst
b/clang-tools-extra/docs/ReleaseNotes.rst
index 8cf2006172d3f..ea80502735ede 100644
--- a/clang-tools-extra/docs/ReleaseNotes.rst
+++ b/clang-tools-extra/docs/ReleaseNotes.rst
@@ -140,6 +140,10 @@ New check aliases
Changes in existing checks
^^^^^^^^^^^^^^^^^^^^^^^^^^
+- Improved :doc:`bugprone-argument-comment
+ <clang-tidy/checks/bugprone/argument-comment>` to also check for C++11
+ inherited constructors.
+
- Improved :doc:`bugprone-macro-parentheses
<clang-tidy/checks/bugprone/macro-parentheses>` check by printing the macro
definition in the warning message if the macro is defined on command line.
diff --git
a/clang-tools-extra/test/clang-tidy/checkers/bugprone/argument-comment-cxx-11-inherited-constructors.cpp
b/clang-tools-extra/test/clang-tidy/checkers/bugprone/argument-comment-cxx-11-inherited-constructors.cpp
new file mode 100644
index 0000000000000..b5e69fa9e92cc
--- /dev/null
+++
b/clang-tools-extra/test/clang-tidy/checkers/bugprone/argument-comment-cxx-11-inherited-constructors.cpp
@@ -0,0 +1,22 @@
+// RUN: %check_clang_tidy -std=c++11-or-later %s bugprone-argument-comment %t
+
+struct Base {
+ explicit Base(int val) {}
+};
+
+struct Over : public Base {
+ using Base::Base;
+};
+
+int wrong() {
+ Base b{/*vall=*/2};
+// CHECK-NOTES: [[@LINE-1]]:10: warning: argument name 'vall' in comment does
not match parameter name 'val'
+// CHECK-NOTES: [[@LINE-10]]:21: note: 'val' declared here
+// CHECK-FIXES: Base b{/*val=*/2};
+
+ Over o{/*vall=*/3};
+// CHECK-NOTES: [[@LINE-1]]:10: warning: argument name 'vall' in comment does
not match parameter name 'val'
+// CHECK-NOTES: [[@LINE-15]]:21: note: 'val' declared here
+// CHECK-NOTES: [[@LINE-12]]:15: note: actual callee ('Base') is declared here
+// CHECK-FIXES: Over o{/*val=*/3};
+}
``````````
</details>
https://github.com/llvm/llvm-project/pull/179105
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits