[Clang-Tidy: modernize] Fix for modernize-redundant-void-arg: complains about variable cast to void
Summary:
Hello, i would like to suggest a fix for one of the checks in clang-tidy.The bug was reported in https://bugs.llvm.org/show_bug.cgi?id=32575 where you can find more information.
For example:
```
template <typename T0>
struct S {
template <typename T>
void g() const {
int a;
(void)a;
}
};
void f() {
S<int>().g<int>();
}
```
this piece of code should not trigger any warning by the check modernize-redundant-void-arg but when we execute the following command
```
clang_tidy -checks=-*,modernize-redundant-void-arg test.cpp -- -std=c++11
```
we obtain the following warning:
/Users/eco419/Desktop/clang-tidy.project/void-redundand_2/test.cpp:6:6: warning: redundant void argument list in function declaration [modernize-redundant-void-arg]
(void)a;
^~~~
Reviewers: aaron.ballman, hokein, alexfh, JonasToth
Reviewed By: aaron.ballman, JonasToth
Subscribers: JonasToth, lebedev.ri, cfe-commits
Tags: #clang-tools-extra
Differential Revision: https://reviews.llvm.org/D52135
git-svn-id: https://llvm.org/svn/llvm-project/clang-tools-extra/trunk@342388 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/clang-tidy/modernize/RedundantVoidArgCheck.cpp b/clang-tidy/modernize/RedundantVoidArgCheck.cpp
index 51dc5a2..ea49ab7 100644
--- a/clang-tidy/modernize/RedundantVoidArgCheck.cpp
+++ b/clang-tidy/modernize/RedundantVoidArgCheck.cpp
@@ -49,7 +49,7 @@
return;
Finder->addMatcher(functionDecl(parameterCountIs(0), unless(isImplicit()),
- unless(isExternC()))
+ unless(isInstantiated()), unless(isExternC()))
.bind(FunctionId),
this);
Finder->addMatcher(typedefNameDecl().bind(TypedefId), this);
diff --git a/test/clang-tidy/modernize-redundant-void-arg.cpp b/test/clang-tidy/modernize-redundant-void-arg.cpp
index 750e5c1..453a481 100644
--- a/test/clang-tidy/modernize-redundant-void-arg.cpp
+++ b/test/clang-tidy/modernize-redundant-void-arg.cpp
@@ -488,3 +488,64 @@
// CHECK-MESSAGES: :[[@LINE-1]]:6: warning: redundant void argument list in lambda expression [modernize-redundant-void-arg]
// CHECK-FIXES: []() BODY;
}
+
+struct S_1 {
+ void g_1(void) const {
+ // CHECK-MESSAGES: :[[@LINE-1]]:11: warning: redundant void argument list in function definition [modernize-redundant-void-arg]
+ // CHECK-FIXES: void g_1() const {
+ int a;
+ (void)a;
+ }
+
+ void g_2() const {
+ int a;
+ (void)a;
+ }
+};
+
+template <typename T0>
+struct S_2 {
+ void g_1(void) const {
+ // CHECK-MESSAGES: :[[@LINE-1]]:11: warning: redundant void argument list in function definition [modernize-redundant-void-arg]
+ // CHECK-FIXES: void g_1() const {
+ int a;
+ (void)a;
+ }
+
+ void g_2() const {
+ int a;
+ (void)a;
+ }
+};
+
+template <typename T0>
+struct S_3 {
+ template <typename T1>
+ void g_1(void) const {
+ // CHECK-MESSAGES: :[[@LINE-1]]:11: warning: redundant void argument list in function definition [modernize-redundant-void-arg]
+ // CHECK-FIXES: void g_1() const {
+ int a;
+ (void)a;
+ }
+ template <typename T2>
+ void g_2() const {
+ int a;
+ (void)a;
+ }
+};
+
+template <typename T1>
+void g_3(void) {
+ // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: redundant void argument list in function definition [modernize-redundant-void-arg]
+ // CHECK-FIXES: void g_3(){
+ int a;
+ (void)a;
+}
+
+//Template instantiation
+void f_testTemplate() {
+ S_1();
+ S_2<int>();
+ S_3<int>();
+ g_3<int>();
+}