hokein created this revision.
hokein added a reviewer: ilya-biryukov.
Herald added a subscriber: xazax.hun.
Herald added a project: clang.

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D67654

Files:
  clang-tools-extra/clang-tidy/utils/LexerUtils.h
  
clang-tools-extra/test/clang-tidy/readability-isolate-declaration-no-infinite-loop.cpp


Index: 
clang-tools-extra/test/clang-tidy/readability-isolate-declaration-no-infinite-loop.cpp
===================================================================
--- /dev/null
+++ 
clang-tools-extra/test/clang-tidy/readability-isolate-declaration-no-infinite-loop.cpp
@@ -0,0 +1,7 @@
+// RUN: %check_clang_tidy -expect-clang-tidy-error %s 
readability-isolate-declaration %t
+
+int main(){
+    int a, b
+    // CHECK-MESSAGES: [[@LINE-1]]:3: warning: multiple declarations in a 
single statement reduces readability
+    // CHECK-MESSAGES: [[@LINE-2]]:11: error: expected ';' at end of 
declaration [clang-diagnostic-error]
+}
Index: clang-tools-extra/clang-tidy/utils/LexerUtils.h
===================================================================
--- clang-tools-extra/clang-tidy/utils/LexerUtils.h
+++ clang-tools-extra/clang-tidy/utils/LexerUtils.h
@@ -10,6 +10,7 @@
 #define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_UTILS_LEXER_UTILS_H
 
 #include "clang/AST/ASTContext.h"
+#include "clang/Basic/TokenKinds.h"
 #include "clang/Lex/Lexer.h"
 
 namespace clang {
@@ -62,14 +63,12 @@
                                     TokenKinds... TKs) {
   while (true) {
     Optional<Token> CurrentToken = Lexer::findNextToken(Start, SM, LangOpts);
-
-    if (!CurrentToken)
+    if (!CurrentToken || CurrentToken->is(tok::eof))
       return SourceLocation();
 
     Token PotentialMatch = *CurrentToken;
     if (PotentialMatch.isOneOf(TK, TKs...))
       return PotentialMatch.getLocation();
-
     Start = PotentialMatch.getLastLoc();
   }
 }


Index: clang-tools-extra/test/clang-tidy/readability-isolate-declaration-no-infinite-loop.cpp
===================================================================
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/readability-isolate-declaration-no-infinite-loop.cpp
@@ -0,0 +1,7 @@
+// RUN: %check_clang_tidy -expect-clang-tidy-error %s readability-isolate-declaration %t
+
+int main(){
+    int a, b
+    // CHECK-MESSAGES: [[@LINE-1]]:3: warning: multiple declarations in a single statement reduces readability
+    // CHECK-MESSAGES: [[@LINE-2]]:11: error: expected ';' at end of declaration [clang-diagnostic-error]
+}
Index: clang-tools-extra/clang-tidy/utils/LexerUtils.h
===================================================================
--- clang-tools-extra/clang-tidy/utils/LexerUtils.h
+++ clang-tools-extra/clang-tidy/utils/LexerUtils.h
@@ -10,6 +10,7 @@
 #define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_UTILS_LEXER_UTILS_H
 
 #include "clang/AST/ASTContext.h"
+#include "clang/Basic/TokenKinds.h"
 #include "clang/Lex/Lexer.h"
 
 namespace clang {
@@ -62,14 +63,12 @@
                                     TokenKinds... TKs) {
   while (true) {
     Optional<Token> CurrentToken = Lexer::findNextToken(Start, SM, LangOpts);
-
-    if (!CurrentToken)
+    if (!CurrentToken || CurrentToken->is(tok::eof))
       return SourceLocation();
 
     Token PotentialMatch = *CurrentToken;
     if (PotentialMatch.isOneOf(TK, TKs...))
       return PotentialMatch.getLocation();
-
     Start = PotentialMatch.getLastLoc();
   }
 }
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to