File tree Expand file tree Collapse file tree 2 files changed +31
-1
lines changed Expand file tree Collapse file tree 2 files changed +31
-1
lines changed Original file line number Diff line number Diff line change 7
7
// ===----------------------------------------------------------------------===//
8
8
9
9
#include " UseDesignatedInitializersCheck.h"
10
+ #include " clang/AST/APValue.h"
10
11
#include " clang/AST/Decl.h"
11
12
#include " clang/AST/Expr.h"
12
13
#include " clang/AST/Stmt.h"
@@ -53,10 +54,19 @@ AST_MATCHER_FUNCTION(::internal::Matcher<CXXRecordDecl>, hasBaseWithFields) {
53
54
return hasAnyBase (hasType (cxxRecordDecl (has (fieldDecl ()))));
54
55
}
55
56
57
+ AST_MATCHER (FieldDecl, isAnonymousDecl) {
58
+ if (const auto *Record =
59
+ Node.getType ().getCanonicalType ()->getAsRecordDecl ()) {
60
+ return Record->isAnonymousStructOrUnion () || !Record->getIdentifier ();
61
+ }
62
+ return false ;
63
+ }
64
+
56
65
void UseDesignatedInitializersCheck::registerMatchers (MatchFinder *Finder) {
57
66
Finder->addMatcher (
58
67
initListExpr (
59
- hasType (cxxRecordDecl (isAggregate (), unless (hasBaseWithFields ()))
68
+ hasType (cxxRecordDecl (isAggregate (), unless (hasBaseWithFields ()),
69
+ unless (has (fieldDecl (isAnonymousDecl ()))))
60
70
.bind (" type" )),
61
71
unless (IgnoreSingleElementAggregates ? hasSingleElement ()
62
72
: unless (anything ())),
Original file line number Diff line number Diff line change @@ -61,3 +61,23 @@ S2 s27 = template2<S2>();
61
61
struct S5 : S2 { int x, y; };
62
62
63
63
S5 s51 {1 , 2 , .x = 3 , .y = 4 };
64
+
65
+ struct S6 {
66
+ int i;
67
+ struct { int j; } s;
68
+ };
69
+
70
+ S6 s61 {1 , 2 };
71
+
72
+ struct S7 {
73
+ union {
74
+ int k;
75
+ double d;
76
+ } u;
77
+ };
78
+
79
+ S7 s71 {1 };
80
+
81
+ struct S8 : S7 { int i; };
82
+
83
+ S8 s81{1 , 2 };
You can’t perform that action at this time.
0 commit comments