This revision was automatically updated to reflect the committed changes.
Closed by commit rL296598: [clang-tidy] Fix handling of methods with 
try-statement as a body in modernize… (authored by alexfh).

Changed prior to commit:
  https://reviews.llvm.org/D30002?vs=88582&id=90136#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D30002

Files:
  clang-tools-extra/trunk/clang-tidy/modernize/UseOverrideCheck.cpp
  clang-tools-extra/trunk/test/clang-tidy/modernize-use-override.cpp


Index: clang-tools-extra/trunk/clang-tidy/modernize/UseOverrideCheck.cpp
===================================================================
--- clang-tools-extra/trunk/clang-tidy/modernize/UseOverrideCheck.cpp
+++ clang-tools-extra/trunk/clang-tidy/modernize/UseOverrideCheck.cpp
@@ -147,14 +147,13 @@
       // end of the declaration of the function, but prefer to put it on the
       // same line as the declaration if the beginning brace for the start of
       // the body falls on the next line.
-      Token LastNonCommentToken;
-      for (Token T : Tokens) {
-        if (!T.is(tok::comment)) {
-          LastNonCommentToken = T;
-        }
-      }
-      InsertLoc = LastNonCommentToken.getEndLoc();
       ReplacementText = " override";
+      auto LastTokenIter = std::prev(Tokens.end());
+      // When try statement is used instead of compound statement as
+      // method body - insert override keyword before it.
+      if (LastTokenIter->is(tok::kw_try))
+        LastTokenIter = std::prev(LastTokenIter);
+      InsertLoc = LastTokenIter->getEndLoc();
     }
 
     if (!InsertLoc.isValid()) {
Index: clang-tools-extra/trunk/test/clang-tidy/modernize-use-override.cpp
===================================================================
--- clang-tools-extra/trunk/test/clang-tidy/modernize-use-override.cpp
+++ clang-tools-extra/trunk/test/clang-tidy/modernize-use-override.cpp
@@ -288,3 +288,17 @@
 };
 template <> void MembersOfSpecializations<3>::a() {}
 void ff() { MembersOfSpecializations<3>().a(); };
+
+// In case try statement is used as a method body,
+// make sure that override fix is placed before try keyword.
+struct TryStmtAsBody : public Base {
+  void a() try
+  // CHECK-MESSAGES: :[[@LINE-1]]:8: warning: annotate this
+  // CHECK-FIXES: {{^}}  void a() override try
+  { b(); } catch(...) { c(); }
+
+  virtual void d() try
+  // CHECK-MESSAGES: :[[@LINE-1]]:16: warning: prefer using
+  // CHECK-FIXES: {{^}}  void d() override try
+  { e(); } catch(...) { f(); }
+};


Index: clang-tools-extra/trunk/clang-tidy/modernize/UseOverrideCheck.cpp
===================================================================
--- clang-tools-extra/trunk/clang-tidy/modernize/UseOverrideCheck.cpp
+++ clang-tools-extra/trunk/clang-tidy/modernize/UseOverrideCheck.cpp
@@ -147,14 +147,13 @@
       // end of the declaration of the function, but prefer to put it on the
       // same line as the declaration if the beginning brace for the start of
       // the body falls on the next line.
-      Token LastNonCommentToken;
-      for (Token T : Tokens) {
-        if (!T.is(tok::comment)) {
-          LastNonCommentToken = T;
-        }
-      }
-      InsertLoc = LastNonCommentToken.getEndLoc();
       ReplacementText = " override";
+      auto LastTokenIter = std::prev(Tokens.end());
+      // When try statement is used instead of compound statement as
+      // method body - insert override keyword before it.
+      if (LastTokenIter->is(tok::kw_try))
+        LastTokenIter = std::prev(LastTokenIter);
+      InsertLoc = LastTokenIter->getEndLoc();
     }
 
     if (!InsertLoc.isValid()) {
Index: clang-tools-extra/trunk/test/clang-tidy/modernize-use-override.cpp
===================================================================
--- clang-tools-extra/trunk/test/clang-tidy/modernize-use-override.cpp
+++ clang-tools-extra/trunk/test/clang-tidy/modernize-use-override.cpp
@@ -288,3 +288,17 @@
 };
 template <> void MembersOfSpecializations<3>::a() {}
 void ff() { MembersOfSpecializations<3>().a(); };
+
+// In case try statement is used as a method body,
+// make sure that override fix is placed before try keyword.
+struct TryStmtAsBody : public Base {
+  void a() try
+  // CHECK-MESSAGES: :[[@LINE-1]]:8: warning: annotate this
+  // CHECK-FIXES: {{^}}  void a() override try
+  { b(); } catch(...) { c(); }
+
+  virtual void d() try
+  // CHECK-MESSAGES: :[[@LINE-1]]:16: warning: prefer using
+  // CHECK-FIXES: {{^}}  void d() override try
+  { e(); } catch(...) { f(); }
+};
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to