[PATCH] D46027: [clang-tidy] Fix PR35824
Gábor Horváth via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Wed Nov 27 11:13:52 PST 2019
This revision was automatically updated to reflect the committed changes.
Closed by commit rG5c5e860535d8: [clang-tidy] Fix PR35824 (authored by xazax.hun).
Herald added a project: clang.
Changed prior to commit:
https://reviews.llvm.org/D46027?vs=231078&id=231301#toc
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D46027/new/
https://reviews.llvm.org/D46027
Files:
clang-tools-extra/clang-tidy/bugprone/SuspiciousSemicolonCheck.cpp
clang-tools-extra/test/clang-tidy/bugprone-suspicious-semicolon-constexpr.cpp
Index: clang-tools-extra/test/clang-tidy/bugprone-suspicious-semicolon-constexpr.cpp
===================================================================
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/bugprone-suspicious-semicolon-constexpr.cpp
@@ -0,0 +1,31 @@
+// RUN: %check_clang_tidy %s bugprone-suspicious-semicolon %t -- -- -std=c++17
+
+void fail()
+{
+ int x = 0;
+ if(x > 5); (void)x;
+ // CHECK-MESSAGES: :[[@LINE-1]]:12: warning: potentially unintended semicolon [bugprone-suspicious-semicolon]
+ // CHECK-FIXES: if(x > 5) (void)x;
+}
+
+template <int X>
+int foo(int a) {
+ if constexpr(X > 0) {
+ return a;
+ }
+ return a + 1;
+}
+
+template <int X>
+int foo2(int a) {
+ // FIXME: diagnose the case below. See https://reviews.llvm.org/D46234
+ // for details.
+ if constexpr(X > 0);
+ return a;
+ return a + 1;
+}
+
+int main(void) {
+ foo2<0>(1);
+ return foo<0>(1);
+}
Index: clang-tools-extra/clang-tidy/bugprone/SuspiciousSemicolonCheck.cpp
===================================================================
--- clang-tools-extra/clang-tidy/bugprone/SuspiciousSemicolonCheck.cpp
+++ clang-tools-extra/clang-tidy/bugprone/SuspiciousSemicolonCheck.cpp
@@ -20,7 +20,8 @@
void SuspiciousSemicolonCheck::registerMatchers(MatchFinder *Finder) {
Finder->addMatcher(
stmt(anyOf(ifStmt(hasThen(nullStmt().bind("semi")),
- unless(hasElse(stmt()))),
+ unless(hasElse(stmt())),
+ unless(isConstexpr())),
forStmt(hasBody(nullStmt().bind("semi"))),
cxxForRangeStmt(hasBody(nullStmt().bind("semi"))),
whileStmt(hasBody(nullStmt().bind("semi")))))
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D46027.231301.patch
Type: text/x-patch
Size: 1734 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20191127/f0c738a7/attachment-0001.bin>
More information about the cfe-commits
mailing list