diff options
author | Malcolm Parsons <malcolm.parsons@gmail.com> | 2020-01-14 09:54:31 +0000 |
---|---|---|
committer | Malcolm Parsons <malcolm.parsons@gmail.com> | 2020-01-14 10:05:12 +0000 |
commit | 45924eb4671692b3fa9fd52fe39c81ec0647a848 (patch) | |
tree | 2abb870d6edabd239496aa22d0841dfb48084e95 | |
parent | ec6579fc047f9ac18588b833dfde0b69064e013a (diff) | |
download | bcm5719-llvm-45924eb4671692b3fa9fd52fe39c81ec0647a848.tar.gz bcm5719-llvm-45924eb4671692b3fa9fd52fe39c81ec0647a848.zip |
[clang-tidy] Ignore implicit casts in modernize-use-default-member-init
Summary:
Initialising a pointer from nullptr involves an implicit cast.
Ignore it after getting initialiser from InitListExpr.
Fixes: PR44440
Reviewers: aaron.ballman, alexfh, JonasToth
Reviewed By: JonasToth
Subscribers: xazax.hun, cfe-commits
Tags: #clang
Differential Revision: https://reviews.llvm.org/D72630
-rw-r--r-- | clang-tools-extra/clang-tidy/modernize/UseDefaultMemberInitCheck.cpp | 2 | ||||
-rw-r--r-- | clang-tools-extra/test/clang-tidy/checkers/modernize-use-default-member-init.cpp | 8 |
2 files changed, 5 insertions, 5 deletions
diff --git a/clang-tools-extra/clang-tidy/modernize/UseDefaultMemberInitCheck.cpp b/clang-tools-extra/clang-tidy/modernize/UseDefaultMemberInitCheck.cpp index 1e59acb1ff1..e99a90ffba5 100644 --- a/clang-tools-extra/clang-tidy/modernize/UseDefaultMemberInitCheck.cpp +++ b/clang-tools-extra/clang-tidy/modernize/UseDefaultMemberInitCheck.cpp @@ -137,7 +137,7 @@ static const Expr *ignoreUnaryPlus(const Expr *E) { static const Expr *getInitializer(const Expr *E) { auto *InitList = dyn_cast<InitListExpr>(E); if (InitList && InitList->getNumInits() == 1) - return InitList->getInit(0); + return InitList->getInit(0)->IgnoreParenImpCasts(); return E; } diff --git a/clang-tools-extra/test/clang-tidy/checkers/modernize-use-default-member-init.cpp b/clang-tools-extra/test/clang-tidy/checkers/modernize-use-default-member-init.cpp index 5af9855835c..0dffeea1c9b 100644 --- a/clang-tools-extra/test/clang-tidy/checkers/modernize-use-default-member-init.cpp +++ b/clang-tools-extra/test/clang-tidy/checkers/modernize-use-default-member-init.cpp @@ -291,7 +291,7 @@ struct ExistingInt { int e1{}; int e2 = 0; int e3 = {5}; - int e4 = 5; + int e4{5}; int e5 = -5; int e6 = +5; }; @@ -315,7 +315,7 @@ struct ExistingDouble { double e1{}; double e2 = 0.0; double e3 = 5.0; - double e4 = -5.0; + double e4{-5.0}; double e5 = +5.0; }; @@ -333,7 +333,7 @@ struct ExistingBool { // CHECK-FIXES: ExistingBool(long) : e1(true), e2(true) {} bool e1{}; bool e2 = false; - bool e3 = true; + bool e3{true}; }; struct ExistingEnum { @@ -365,7 +365,7 @@ struct ExistingPointer { // CHECK-FIXES: ExistingPointer(long) : e4(&e2) {} int *e1{}; int *e2 = 0; - int *e3 = nullptr; + int *e3{nullptr}; int **e4 = &e1; }; |