@@ -131,6 +131,11 @@ module ReservedNames {
131131 scope = MacroScope ( ) and
132132 cNameSpace = MacroNameSpace ( ) and
133133 identifierDescription = "Macro parameter"
134+ or
135+ e .( PreprocessorUndef ) .getName ( ) = identifierName and
136+ scope = MacroScope ( ) and
137+ cNameSpace = MacroNameSpace ( ) and
138+ identifierDescription = "Undef"
134139 )
135140 }
136141
@@ -148,7 +153,13 @@ module ReservedNames {
148153
149154 module TargetedCLibrary = CStandardLibrary:: C11;
150155
151- predicate isAReservedIdentifier ( Element m , string message ) {
156+ /**
157+ * Holds if the given C program element is a reserved identifier according to the C11 standard or MISRA.
158+ *
159+ * @param requireHeaderIncluded false if we don't require
160+ */
161+ predicate isAReservedIdentifier ( Element m , string message , boolean requireHeaderIncluded ) {
162+ requireHeaderIncluded = [ true , false ] and
152163 exists (
153164 string name , Scope scope , CNameSpace cNameSpace , string reason , string identifierDescription
154165 |
@@ -187,8 +198,8 @@ module ReservedNames {
187198 // > unless explicitly stated otherwise (see 7.1.4).
188199 exists ( string header |
189200 TargetedCLibrary:: hasMacroName ( header , name , _) and
190- // The relevant header is included directly or transitively by the file
191- m .getFile ( ) .getAnIncludedFile * ( ) .getBaseName ( ) = header and
201+ // The relevant header is included directly or transitively by the file, or we don't apply that requirement
202+ ( m .getFile ( ) .getAnIncludedFile * ( ) .getBaseName ( ) = header or requireHeaderIncluded = false ) and
192203 reason =
193204 "declares a name reserved for a macro from the " + TargetedCLibrary:: getName ( ) +
194205 " standard library header '" + header + "'"
@@ -272,8 +283,8 @@ module ReservedNames {
272283 or
273284 scope = MacroScope ( )
274285 ) and
275- // The relevant header is included directly or transitively by the file
276- m .getFile ( ) .getAnIncludedFile * ( ) .getBaseName ( ) = header and
286+ // The relevant header is included directly or transitively by the file, or we don't apply that requirement
287+ ( m .getFile ( ) .getAnIncludedFile * ( ) .getBaseName ( ) = header or requireHeaderIncluded = false ) and
277288 reason =
278289 "declares a reserved name from the " + TargetedCLibrary:: getName ( ) +
279290 " standard library header '" + header +
0 commit comments