[PATCH] D126735: [clang-tidy] Silence modernize-redundant-void-arg in the case of vexing parses
George Burgess IV via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Wed Jul 13 12:56:56 PDT 2022
george.burgess.iv updated this revision to Diff 444397.
george.burgess.iv added a comment.
Rebased on top of 891319f654c102572cf7028ed04bbaf6c59e7bff <https://reviews.llvm.org/rG891319f654c102572cf7028ed04bbaf6c59e7bff> as requested; `ninja check-clang-extra docs-clang-tools-html` passes
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D126735/new/
https://reviews.llvm.org/D126735
Files:
clang-tools-extra/clang-tidy/modernize/RedundantVoidArgCheck.cpp
clang-tools-extra/test/clang-tidy/checkers/modernize/redundant-void-arg.cpp
Index: clang-tools-extra/test/clang-tidy/checkers/modernize/redundant-void-arg.cpp
===================================================================
--- clang-tools-extra/test/clang-tidy/checkers/modernize/redundant-void-arg.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/modernize/redundant-void-arg.cpp
@@ -592,3 +592,9 @@
(void)a;
}
#undef return_t
+
+// Explicitly specifying `(void)` is a way to sidestep -Wvexing-parse, so we
+// should not warn about it here.
+void most_vexing_parse() {
+ int foo(void);
+}
Index: clang-tools-extra/clang-tidy/modernize/RedundantVoidArgCheck.cpp
===================================================================
--- clang-tools-extra/clang-tidy/modernize/RedundantVoidArgCheck.cpp
+++ clang-tools-extra/clang-tidy/modernize/RedundantVoidArgCheck.cpp
@@ -109,9 +109,13 @@
}
removeVoidArgumentTokens(Result, SourceRange(Start, End),
"function definition");
- } else
+ } else if (!Function->getLexicalDeclContext()->isFunctionOrMethod()) {
+ // Only do this if our decl context is outside of a function or method;
+ // otherwise, the user may have explicitly written `(void)` to avoid Most
+ // Vexing Parse warnings.
removeVoidArgumentTokens(Result, SourceRange(Start, End),
"function declaration");
+ }
}
bool isMacroIdentifier(const IdentifierTable &Idents, const Token &ProtoToken) {
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D126735.444397.patch
Type: text/x-patch
Size: 1431 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20220713/da27aab4/attachment-0001.bin>
More information about the cfe-commits
mailing list