cxxConstructorDecl(
isDefaultConstructor(), unless(isInstantiated()),
forEachConstructorInitializer(
- allOf(forField(unless(anyOf(isBitField(),
- hasInClassInitializer(anything())))),
- cxxCtorInitializer(isWritten(),
- withInitializer(ignoringImplicit(Init)))
- .bind("default")))),
+ cxxCtorInitializer(
+ forField(unless(anyOf(isBitField(),
+ hasInClassInitializer(anything()),
+ hasParent(recordDecl(isUnion()))))),
+ isWritten(), withInitializer(ignoringImplicit(Init)))
+ .bind("default"))),
this);
Finder->addMatcher(
cxxConstructorDecl(
unless(ast_matchers::isTemplateInstantiation()),
forEachConstructorInitializer(
- allOf(forField(hasInClassInitializer(anything())),
- cxxCtorInitializer(isWritten(),
- withInitializer(ignoringImplicit(Init)))
- .bind("existing")))),
+ cxxCtorInitializer(forField(hasInClassInitializer(anything())),
+ isWritten(),
+ withInitializer(ignoringImplicit(Init)))
+ .bind("existing"))),
this);
}
void UseDefaultMemberInitCheck::checkDefaultInit(
const MatchFinder::MatchResult &Result, const CXXCtorInitializer *Init) {
- const FieldDecl *Field = Init->getMember();
+ const FieldDecl *Field = Init->getAnyMember();
SourceLocation StartLoc = Field->getLocStart();
if (StartLoc.isMacroID() && IgnoreMacros)
forEachConstructorInitializer(
cxxCtorInitializer(isWritten(),
withInitializer(ignoringImplicit(Construct)),
- unless(forField(hasType(isConstQualified()))))
+ unless(forField(hasType(isConstQualified()))),
+ unless(forField(hasParent(recordDecl(isUnion())))))
.bind("init"))),
this);
}
Construct->getArg(0)->isDefaultArgument()) {
if (Init->isAnyMemberInitializer()) {
diag(Init->getSourceLocation(), "initializer for member %0 is redundant")
- << Init->getMember()
+ << Init->getAnyMember()
<< FixItHint::CreateRemoval(Init->getSourceRange());
} else {
diag(Init->getSourceLocation(),
// CHECK-FIXES: const char *s{"foo"};
};
+struct PositiveStruct {
+ PositiveStruct() : s(7) {}
+ // CHECK-FIXES: PositiveStruct() {}
+ struct {
+ int s;
+ // CHECK-MESSAGES: :[[@LINE-1]]:9: warning: use default member initializer for 's'
+ // CHECK-FIXES: int s{7};
+ };
+};
+
template <typename T>
struct NegativeTemplate {
NegativeTemplate() : t() {}