Skip to content

Commit 30bfeae

Browse files
committed
Ignore types inheriting fields
1 parent 8b99092 commit 30bfeae

File tree

2 files changed

+15
-4
lines changed

2 files changed

+15
-4
lines changed

clang-tools-extra/clang-tidy/modernize/UseDesignatedInitializersCheck.cpp

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,12 +48,19 @@ AST_MATCHER(InitListExpr, isFullyDesignated) {
4848
}
4949

5050
AST_MATCHER(InitListExpr, hasSingleElement) { return Node.getNumInits() == 1; }
51+
52+
AST_MATCHER_FUNCTION(::internal::Matcher<CXXRecordDecl>, hasBaseWithFields) {
53+
return hasAnyBase(hasType(cxxRecordDecl(has(fieldDecl()))));
54+
}
55+
5156
void UseDesignatedInitializersCheck::registerMatchers(MatchFinder *Finder) {
5257
Finder->addMatcher(
53-
initListExpr(hasType(cxxRecordDecl(isAggregate()).bind("type")),
54-
unless(IgnoreSingleElementAggregates ? hasSingleElement()
55-
: unless(anything())),
56-
unless(isFullyDesignated()))
58+
initListExpr(
59+
hasType(cxxRecordDecl(isAggregate(), unless(hasBaseWithFields()))
60+
.bind("type")),
61+
unless(IgnoreSingleElementAggregates ? hasSingleElement()
62+
: unless(anything())),
63+
unless(isFullyDesignated()))
5764
.bind("init"),
5865
this);
5966
}

clang-tools-extra/test/clang-tidy/checkers/modernize/use-designated-initializers.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,3 +57,7 @@ S2 s26 = template1<S2>();
5757
template<typename S> S template2() { return {}; }
5858

5959
S2 s27 = template2<S2>();
60+
61+
struct S5: S2 { int x, y; };
62+
63+
S5 s51 {1, 2, .x = 3, .y = 4};

0 commit comments

Comments
 (0)