Skip to content

Commit 35f2c3a

Browse files
cwarner-8702pepsiman
authored andcommitted
[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/D93333
1 parent 9956233 commit 35f2c3a

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

clang-tools-extra/clang-tidy/cppcoreguidelines/ProTypeMemberInitCheck.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -297,6 +297,10 @@ void ProTypeMemberInitCheck::check(const MatchFinder::MatchResult &Result) {
297297
// Skip declarations delayed by late template parsing without a body.
298298
if (!Ctor->getBody())
299299
return;
300+
// Skip out-of-band explicitly defaulted special member functions
301+
// (except the default constructor).
302+
if (Ctor->isExplicitlyDefaulted() && !Ctor->isDefaultConstructor())
303+
return;
300304
checkMissingMemberInitializer(*Result.Context, *Ctor->getParent(), Ctor);
301305
checkMissingBaseClassInitializer(*Result.Context, *Ctor->getParent(), Ctor);
302306
} else if (const auto *Record =

clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines-pro-type-member-init.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -501,3 +501,19 @@ struct NegativeImplicitInheritedCtor : NegativeImplicitInheritedCtorBase {
501501
void Bug33557() {
502502
NegativeImplicitInheritedCtor I(5);
503503
}
504+
505+
struct NegativeDefaultedCtorOutOfDecl {
506+
NegativeDefaultedCtorOutOfDecl(const NegativeDefaultedCtorOutOfDecl &);
507+
int F;
508+
};
509+
510+
NegativeDefaultedCtorOutOfDecl::NegativeDefaultedCtorOutOfDecl(const NegativeDefaultedCtorOutOfDecl &) = default;
511+
512+
struct PositiveDefaultConstructorOutOfDecl {
513+
PositiveDefaultConstructorOutOfDecl();
514+
int F;
515+
// CHECK-FIXES: int F{};
516+
};
517+
518+
PositiveDefaultConstructorOutOfDecl::PositiveDefaultConstructorOutOfDecl() = default;
519+
// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: constructor does not initialize these fields: F

0 commit comments

Comments
 (0)