diff options
| author | Alexander Kornienko <alexfh@google.com> | 2017-03-01 10:16:36 +0000 |
|---|---|---|
| committer | Alexander Kornienko <alexfh@google.com> | 2017-03-01 10:16:36 +0000 |
| commit | eedf7ec07f40ab17fb8d77ed15ae27a65473856a (patch) | |
| tree | 910fb1cd4bc7ea18188365c8743853fc913ef06b /clang-tools-extra/clang-tidy/modernize/UseOverrideCheck.cpp | |
| parent | c84ca256d30272cf958d2f94357b58d872b983bf (diff) | |
| download | bcm5719-llvm-eedf7ec07f40ab17fb8d77ed15ae27a65473856a.tar.gz bcm5719-llvm-eedf7ec07f40ab17fb8d77ed15ae27a65473856a.zip | |
[clang-tidy] Fix handling of methods with try-statement as a body in modernize-use-override
Summary:
Fix generated by modernize-use-override caused syntax error when method
used try-statement as a body. `override` keyword was inserted after last
declaration token which happened to be a `try` keyword.
This fixes PR27119.
Reviewers: ehsan, djasper, alexfh
Reviewed By: alexfh
Subscribers: JDevlieghere, cfe-commits
Tags: #clang-tools-extra
Patch by Paweł Żukowski!
Differential Revision: https://reviews.llvm.org/D30002
llvm-svn: 296598
Diffstat (limited to 'clang-tools-extra/clang-tidy/modernize/UseOverrideCheck.cpp')
| -rw-r--r-- | clang-tools-extra/clang-tidy/modernize/UseOverrideCheck.cpp | 13 |
1 files changed, 6 insertions, 7 deletions
diff --git a/clang-tools-extra/clang-tidy/modernize/UseOverrideCheck.cpp b/clang-tools-extra/clang-tidy/modernize/UseOverrideCheck.cpp index be01d21586d..f6202c7279b 100644 --- a/clang-tools-extra/clang-tidy/modernize/UseOverrideCheck.cpp +++ b/clang-tools-extra/clang-tidy/modernize/UseOverrideCheck.cpp @@ -147,14 +147,13 @@ void UseOverrideCheck::check(const MatchFinder::MatchResult &Result) { // 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()) { |

