summaryrefslogtreecommitdiffstats
path: root/clang-tools-extra/clang-tidy/modernize
diff options
context:
space:
mode:
authorMitchell Balan <mitchell@stellarscience.com>2019-11-20 15:36:45 -0500
committerMitchell Balan <mitchell@stellarscience.com>2019-11-20 18:08:37 -0500
commit24aafcadff3851ec3a0c42303fec63e815b19566 (patch)
tree2761ee140707f24772e277bea72e765204e6cb99 /clang-tools-extra/clang-tidy/modernize
parenta329cf69696f1d1103c569b4c4d68d212b204710 (diff)
downloadbcm5719-llvm-24aafcadff3851ec3a0c42303fec63e815b19566.tar.gz
bcm5719-llvm-24aafcadff3851ec3a0c42303fec63e815b19566.zip
[clang-tidy] modernize-use-equals-default avoid adding redundant semicolons
Summary: `modernize-use-equals-default` replaces default constructors/destructors with `= default;`. When the optional semicolon after a member function is present, this results in two consecutive semicolons. This patch checks to see if the next non-comment token after the code to be replaced is a semicolon, and if so offers a replacement of `= default` rather than `= default;`. This patch adds trailing comments and semicolons to about 5 existing tests. Reviewers: malcolm.parsons, angelgarcia, aaron.ballman, alexfh Patch by: poelmanc Subscribers: MyDeveloperDay, JonasToth, cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D70144
Diffstat (limited to 'clang-tools-extra/clang-tidy/modernize')
-rw-r--r--clang-tools-extra/clang-tidy/modernize/UseEqualsDefaultCheck.cpp12
1 files changed, 10 insertions, 2 deletions
diff --git a/clang-tools-extra/clang-tidy/modernize/UseEqualsDefaultCheck.cpp b/clang-tools-extra/clang-tidy/modernize/UseEqualsDefaultCheck.cpp
index 991eada514d..0309fa8d0a3 100644
--- a/clang-tools-extra/clang-tidy/modernize/UseEqualsDefaultCheck.cpp
+++ b/clang-tools-extra/clang-tidy/modernize/UseEqualsDefaultCheck.cpp
@@ -10,6 +10,7 @@
#include "clang/AST/ASTContext.h"
#include "clang/ASTMatchers/ASTMatchFinder.h"
#include "clang/Lex/Lexer.h"
+#include "../utils/LexerUtils.h"
using namespace clang::ast_matchers;
@@ -302,9 +303,16 @@ void UseEqualsDefaultCheck::check(const MatchFinder::MatchResult &Result) {
auto Diag = diag(Location, "use '= default' to define a trivial " +
SpecialFunctionName);
- if (ApplyFix)
- Diag << FixItHint::CreateReplacement(Body->getSourceRange(), "= default;")
+ if (ApplyFix) {
+ // Skipping comments, check for a semicolon after Body->getSourceRange()
+ Optional<Token> Token = utils::lexer::findNextTokenSkippingComments(
+ Body->getSourceRange().getEnd().getLocWithOffset(1),
+ Result.Context->getSourceManager(), Result.Context->getLangOpts());
+ StringRef Replacement =
+ Token && Token->is(tok::semi) ? "= default" : "= default;";
+ Diag << FixItHint::CreateReplacement(Body->getSourceRange(), Replacement)
<< RemoveInitializers;
+ }
}
} // namespace modernize
OpenPOWER on IntegriCloud