Clang Flag: -Wreserved-identifier / -Wno-reserved-identifier

From emmtrix Wiki
Jump to navigation Jump to search
This article covers two Clang compiler flags, -Wreserved-identifier and -Wno-reserved-identifier, which control warnings related to reserved identifiers in C and C++ code.

The -Wreserved-identifier flag, which is inactive by default, can be enabled to warn developers when identifier names are used in a manner that is reserved by the C or C++ standards. This includes using reserved names as identifiers for external symbols or defining macros with reserved names. Turning this flag on helps ensure that the code adheres to the language standards by avoiding potential conflicts with compiler or system-implemented names.

On the other hand, -Wno-reserved-identifier is active by default and suppresses warnings about certain reserved name uses, such as reserved module names or user-defined literal suffixes that are reserved. This may be useful for working with existing codebases where changing identifier names might not be feasible or would lead to significant refactoring.

Developers are encouraged to enable -Wreserved-identifier in projects to maintain compatibility with the standards and ensure that code does not inadvertently clash with names that compilers internally reserve for system or language purposes. Conversely, when working with legacy systems or when strict adherence to reserved identifier rules is not critical, -Wno-reserved-identifier can be used to suppress related warnings for smoother compilation.

 
AI Generated

Supergroups

Subroups

Warnings/Remarks

Default Active (Deactivate with -Wno-reserved-identifier)

warn_reserved_module_name warning: A is a reserved name for a module
warn_user_literal_reserved
warning: user-defined literal suffixes
not starting with '_'
containing '__'
are reserved
; no literal will invoke this operator
 

Default Inactive (Activate with -Wreserved-identifier)

warn_reserved_extern_symbol
warning: identifier A is reserved because
it starts with '_' at global scope
it starts with '_' and has C language linkage
it starts with '__'
it starts with '_' followed by a capital letter
it contains '__'

warn_pp_macro_is_reserved_id warning: macro name is a reserved identifier