From 45924eb4671692b3fa9fd52fe39c81ec0647a848 Mon Sep 17 00:00:00 2001 From: Malcolm Parsons Date: Tue, 14 Jan 2020 09:54:31 +0000 Subject: [PATCH] [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 --- .../clang-tidy/modernize/UseDefaultMemberInitCheck.cpp | 2 +- .../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 1e59acb..e99a90f 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(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 5af9855..0dffeea 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; }; -- 2.7.4