@@ -100,7 +100,14 @@ predicate isCIdentifier(
100100 ) and
101101 (
102102 if e instanceof UserType
103- then cNameSpace = TagNameSpace ( )
103+ then
104+ if e instanceof TypedefType
105+ then
106+ // Typedef types are in the ordinary namespace
107+ cNameSpace = OrdinaryNameSpace ( )
108+ else
109+ // Other user-defined types are in the tag namespace
110+ cNameSpace = TagNameSpace ( )
104111 else
105112 if ( e instanceof MemberVariable or e instanceof MemberFunction )
106113 then cNameSpace = MemberNameSpace ( )
@@ -219,8 +226,23 @@ query predicate problems(Element m, string message) {
219226 TargetedCLibrary:: hasFunctionName ( header , _, "" , name , _, _, _) and
220227 ( cNameSpace = OrdinaryNameSpace ( ) or cNameSpace = MacroNameSpace ( ) )
221228 or
222- TargetedCLibrary:: hasTypeName ( header , _, name ) and
223- ( cNameSpace = TagNameSpace ( ) or cNameSpace = MacroNameSpace ( ) )
229+ exists ( string typeName |
230+ TargetedCLibrary:: hasTypeName ( header , _, typeName ) and
231+ // Strip struct/union/enum prefix
232+ name = typeName .regexpReplaceAll ( "^(struct|union|enum) " , "" )
233+ |
234+ (
235+ if typeName .regexpMatch ( "^(struct|union|enum) " )
236+ then
237+ // struct, union and enum types are in the tag namespace
238+ cNameSpace = TagNameSpace ( )
239+ else
240+ // typedef and therefore part of the ordinary namespace
241+ cNameSpace = OrdinaryNameSpace ( )
242+ )
243+ or
244+ cNameSpace = MacroNameSpace ( )
245+ )
224246 or
225247 exists ( string declaringType , Class c |
226248 TargetedCLibrary:: hasMemberVariableName ( header , _, declaringType , name , _)
0 commit comments