[llvm-branch-commits] [clang-tools-extra] 35f2c3a - [clang-tidy] cppcoreguidelines-pro-type-member-init: suppress warning for default member funcs
Author: Chris Warner Date: 2020-12-20T11:22:41Z New Revision: 35f2c3a8b41fd3b6ef88d013a7c3ed9478b765e4 URL: https://github.com/llvm/llvm-project/commit/35f2c3a8b41fd3b6ef88d013a7c3ed9478b765e4 DIFF: https://github.com/llvm/llvm-project/commit/35f2c3a8b41fd3b6ef88d013a7c3ed9478b765e4.diff LOG: [clang-tidy] cppcoreguidelines-pro-type-member-init: suppress warning for default member funcs Modify the cppcoreguidelines-pro-type-member-init checker to ignore warnings from the move and copy-constructors when they are compiler defined with `= default` outside of the type declaration. Reported as [LLVM bug 36819](https://bugs.llvm.org/show_bug.cgi?id=36819) Reviewed By: malcolm.parsons Differential Revision: https://reviews.llvm.org/D9 Added: Modified: clang-tools-extra/clang-tidy/cppcoreguidelines/ProTypeMemberInitCheck.cpp clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines-pro-type-member-init.cpp Removed: diff --git a/clang-tools-extra/clang-tidy/cppcoreguidelines/ProTypeMemberInitCheck.cpp b/clang-tools-extra/clang-tidy/cppcoreguidelines/ProTypeMemberInitCheck.cpp index a223d215af1b..67856be843e7 100644 --- a/clang-tools-extra/clang-tidy/cppcoreguidelines/ProTypeMemberInitCheck.cpp +++ b/clang-tools-extra/clang-tidy/cppcoreguidelines/ProTypeMemberInitCheck.cpp @@ -297,6 +297,10 @@ void ProTypeMemberInitCheck::check(const MatchFinder::MatchResult &Result) { // Skip declarations delayed by late template parsing without a body. if (!Ctor->getBody()) return; +// Skip out-of-band explicitly defaulted special member functions +// (except the default constructor). +if (Ctor->isExplicitlyDefaulted() && !Ctor->isDefaultConstructor()) + return; checkMissingMemberInitializer(*Result.Context, *Ctor->getParent(), Ctor); checkMissingBaseClassInitializer(*Result.Context, *Ctor->getParent(), Ctor); } else if (const auto *Record = diff --git a/clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines-pro-type-member-init.cpp b/clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines-pro-type-member-init.cpp index 28230dd6952e..403f28baf99d 100644 --- a/clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines-pro-type-member-init.cpp +++ b/clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines-pro-type-member-init.cpp @@ -501,3 +501,19 @@ struct NegativeImplicitInheritedCtor : NegativeImplicitInheritedCtorBase { void Bug33557() { NegativeImplicitInheritedCtor I(5); } + +struct NegativeDefaultedCtorOutOfDecl { + NegativeDefaultedCtorOutOfDecl(const NegativeDefaultedCtorOutOfDecl &); + int F; +}; + +NegativeDefaultedCtorOutOfDecl::NegativeDefaultedCtorOutOfDecl(const NegativeDefaultedCtorOutOfDecl &) = default; + +struct PositiveDefaultConstructorOutOfDecl { + PositiveDefaultConstructorOutOfDecl(); + int F; + // CHECK-FIXES: int F{}; +}; + +PositiveDefaultConstructorOutOfDecl::PositiveDefaultConstructorOutOfDecl() = default; +// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: constructor does not initialize these fields: F ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [clang-tools-extra] d272d3a - [clang-tidy] Ignore implicit casts in modernize-use-default-member-init
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: PR0 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(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; }; ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits