[clang-tools-extra] r262615 - [clang-tidy] Do not emit warnings from misc-suspicious-semicolon when the compilation fails.

Gabor Horvath via cfe-commits cfe-commits at lists.llvm.org
Thu Mar 3 05:08:11 PST 2016


Author: xazax
Date: Thu Mar  3 07:08:11 2016
New Revision: 262615

URL: http://llvm.org/viewvc/llvm-project?rev=262615&view=rev
Log:
[clang-tidy] Do not emit warnings from misc-suspicious-semicolon when the compilation fails.

Added:
    clang-tools-extra/trunk/test/clang-tidy/misc-suspicious-semicolon-fail.cpp
Modified:
    clang-tools-extra/trunk/clang-tidy/misc/SuspiciousSemicolonCheck.cpp
    clang-tools-extra/trunk/docs/clang-tidy/checks/misc-suspicious-semicolon.rst

Modified: clang-tools-extra/trunk/clang-tidy/misc/SuspiciousSemicolonCheck.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/misc/SuspiciousSemicolonCheck.cpp?rev=262615&r1=262614&r2=262615&view=diff
==============================================================================
--- clang-tools-extra/trunk/clang-tidy/misc/SuspiciousSemicolonCheck.cpp (original)
+++ clang-tools-extra/trunk/clang-tidy/misc/SuspiciousSemicolonCheck.cpp Thu Mar  3 07:08:11 2016
@@ -7,8 +7,8 @@
 //
 //===----------------------------------------------------------------------===//
 
-#include "../utils/LexerUtils.h"
 #include "SuspiciousSemicolonCheck.h"
+#include "../utils/LexerUtils.h"
 #include "clang/AST/ASTContext.h"
 #include "clang/ASTMatchers/ASTMatchFinder.h"
 
@@ -30,6 +30,9 @@ void SuspiciousSemicolonCheck::registerM
 }
 
 void SuspiciousSemicolonCheck::check(const MatchFinder::MatchResult &Result) {
+  if (Result.Context->getDiagnostics().hasErrorOccurred())
+    return;
+
   const auto *Semicolon = Result.Nodes.getNodeAs<NullStmt>("semi");
   SourceLocation LocStart = Semicolon->getLocStart();
 

Modified: clang-tools-extra/trunk/docs/clang-tidy/checks/misc-suspicious-semicolon.rst
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/docs/clang-tidy/checks/misc-suspicious-semicolon.rst?rev=262615&r1=262614&r2=262615&view=diff
==============================================================================
--- clang-tools-extra/trunk/docs/clang-tidy/checks/misc-suspicious-semicolon.rst (original)
+++ clang-tools-extra/trunk/docs/clang-tidy/checks/misc-suspicious-semicolon.rst Thu Mar  3 07:08:11 2016
@@ -11,7 +11,7 @@ intentional.
 
   .. code-block:: c++
 
-    if(x < y);
+    if (x < y);
     {
       x++;
     }
@@ -22,7 +22,7 @@ the first line, and `x` will be incremen
 
   .. code-block:: c++
 
-    while((line = readLine(file)) != NULL);
+    while ((line = readLine(file)) != NULL);
       processLine(line);
 
 As a result of this code, `processLine()` will only be called once, when the
@@ -32,7 +32,7 @@ the code indicates the intention of the
 
   .. code-block:: c++
 
-    if(x >= y);
+    if (x >= y);
     x -= y;
 
 While the indentation does not imply any nesting, there is simply no valid
@@ -45,7 +45,7 @@ line. For example:
 
   .. code-block:: c++
 
-    while(readWhitespace());
+    while (readWhitespace());
       Token t = readNextToken();
 
 Here the second line is indented in a way that suggests that it is meant to be
@@ -56,14 +56,14 @@ Either remove the indentation from the s
 
   .. code-block:: c++
 
-    while(readWhitespace());
+    while (readWhitespace());
     Token t = readNextToken();
 
 ... or move the semicolon from the end of the first line to a new line:
 
   .. code-block:: c++
 
-    while(readWhitespace())
+    while (readWhitespace())
       ;
 
       Token t = readNextToken();

Added: clang-tools-extra/trunk/test/clang-tidy/misc-suspicious-semicolon-fail.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/misc-suspicious-semicolon-fail.cpp?rev=262615&view=auto
==============================================================================
--- clang-tools-extra/trunk/test/clang-tidy/misc-suspicious-semicolon-fail.cpp (added)
+++ clang-tools-extra/trunk/test/clang-tidy/misc-suspicious-semicolon-fail.cpp Thu Mar  3 07:08:11 2016
@@ -0,0 +1,13 @@
+// RUN: clang-tidy %s -checks="-*,misc-suspicious-semicolon" -- 2>&1 > %t
+// RUN: FileCheck --input-file=%t %s
+
+// Note: This test verifies that, the checker does not emit any warning for
+//       files that do not compile.
+
+bool g();
+
+void f() {
+  if (g());
+  // CHECK-NOT: :[[@LINE-1]]:11: warning: potentially unintended semicolon [misc-suspicious-semicolon]
+  int a
+}




More information about the cfe-commits mailing list