File tree Expand file tree Collapse file tree 5 files changed +60
-4
lines changed Expand file tree Collapse file tree 5 files changed +60
-4
lines changed Original file line number Diff line number Diff line change @@ -106,11 +106,15 @@ void TaggedUnionMemberCountCheck::storeOptions(
106106
107107void TaggedUnionMemberCountCheck::registerMatchers (MatchFinder *Finder) {
108108
109- auto UnionField = fieldDecl ( hasType ( qualType (
110- hasCanonicalType ( recordType ( hasDeclaration ( recordDecl ( isUnion ())))) )));
109+ auto NotFromSystemHeaderOrStdNamespace =
110+ unless ( anyOf ( isExpansionInSystemHeader (), isInStdNamespace ( )));
111111
112- auto EnumField = fieldDecl (hasType (
113- qualType (hasCanonicalType (enumType (hasDeclaration (enumDecl ()))))));
112+ auto UnionField =
113+ fieldDecl (hasType (qualType (hasCanonicalType (recordType (hasDeclaration (
114+ recordDecl (isUnion (), NotFromSystemHeaderOrStdNamespace)))))));
115+
116+ auto EnumField = fieldDecl (hasType (qualType (hasCanonicalType (
117+ enumType (hasDeclaration (enumDecl (NotFromSystemHeaderOrStdNamespace)))))));
114118
115119 auto hasOneUnionField = fieldCountOfKindIsOne (UnionField, UnionMatchBindName);
116120 auto hasOneEnumField = fieldCountOfKindIsOne (EnumField, TagMatchBindName);
Original file line number Diff line number Diff line change @@ -147,3 +147,16 @@ struct Name {\
147147
148148// CHECK-MESSAGES: :[[@LINE+1]]:44: warning: tagged union has more data members (4) than tags (3)
149149DECLARE_TAGGED_UNION_STRUCT (Tags3 , Union4 , TaggedUnionStructFromMacro );
150+
151+ // Typedefed unions from system header files should be ignored when
152+ // we are trying to pinpoint the union part in a user-defined tagged union.
153+ #include "pthread.h"
154+
155+ // This should not be analyzed as a user-defined tagged union,
156+ // even though pthread_mutex_t may be declared as a typedefed union.
157+ struct SystemTypedefedUnionDataMemberShouldBeIgnored {
158+ pthread_mutex_t Mutex ;
159+ enum {
160+ MyEnum
161+ } EnumField ;
162+ };
Original file line number Diff line number Diff line change @@ -308,3 +308,16 @@ void DoNotMatchLambdas() {
308308 } u;
309309 auto L = [e, u] () {};
310310}
311+
312+ // Typedefed unions from system header files should be ignored when
313+ // we are trying to pinpoint the union part in a user-defined tagged union.
314+ #include " pthread.h"
315+
316+ // This should not be analyzed as a user-defined tagged union,
317+ // even though pthread_mutex_t may be declared as a typedefed union.
318+ struct SystemTypedefedUnionDataMemberShouldBeIgnored {
319+ pthread_mutex_t Mutex;
320+ enum {
321+ MyEnum
322+ } EnumField;
323+ };
Original file line number Diff line number Diff line change 147147
148148// CHECK-MESSAGES: :[[@LINE+1]]:44: warning: tagged union has more data members (4) than tags (3)
149149DECLARE_TAGGED_UNION_STRUCT (Tags3, Union4, TaggedUnionStructFromMacro);
150+
151+ // Typedefed unions from system header files should be ignored when
152+ // we are trying to pinpoint the union part in a user-defined tagged union.
153+ #include " pthread.h"
154+
155+ // This should not be analyzed as a user-defined tagged union,
156+ // even though pthread_mutex_t may be declared as a typedefed union.
157+ struct SystemTypedefedUnionDataMemberShouldBeIgnored {
158+ pthread_mutex_t Mutex;
159+ enum {
160+ MyEnum
161+ } EnumField;
162+ };
Original file line number Diff line number Diff line change @@ -307,3 +307,16 @@ void DoNotMatchLambdas() {
307307 } u;
308308 auto L = [e, u] () {};
309309}
310+
311+ // Typedefed unions from system header files should be ignored when
312+ // we are trying to pinpoint the union part in a user-defined tagged union.
313+ #include " pthread.h"
314+
315+ // This should not be analyzed as a user-defined tagged union,
316+ // even though pthread_mutex_t may be declared as a typedefed union.
317+ struct SystemTypedefedUnionDataMemberShouldBeIgnored {
318+ pthread_mutex_t Mutex;
319+ enum {
320+ MyEnum
321+ } EnumField;
322+ };
You can’t perform that action at this time.
0 commit comments