[llvm-branch-commits] [clang-tools-extra] d272d3a - [clang-tidy] Ignore implicit casts in modernize-use-default-member-init

Malcolm Parsons via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Tue Jan 14 01:57:08 PST 2020


Author: Malcolm Parsons
Date: 2020-01-14T09:54:31Z
New Revision: d272d3a1885a82d6ccf5b3d5b6841f79d81e24e5

URL: https://github.com/llvm/llvm-project/commit/d272d3a1885a82d6ccf5b3d5b6841f79d81e24e5
DIFF: https://github.com/llvm/llvm-project/commit/d272d3a1885a82d6ccf5b3d5b6841f79d81e24e5.diff

LOG: [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

Added: 
    

Modified: 
    clang-tools-extra/clang-tidy/modernize/UseDefaultMemberInitCheck.cpp
    clang-tools-extra/test/clang-tidy/checkers/modernize-use-default-member-init.cpp

Removed: 
    


################################################################################
diff  --git a/clang-tools-extra/clang-tidy/modernize/UseDefaultMemberInitCheck.cpp b/clang-tools-extra/clang-tidy/modernize/UseDefaultMemberInitCheck.cpp
index 1e59acb1ff17..e99a90ffba57 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 5af9855835ca..0dffeea1c9b7 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;
 };
 


        


More information about the llvm-branch-commits mailing list