[PATCH] D117522: [clang-tidy] Add modernize-macro-to-enum check
Richard via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Mon Jan 17 16:19:08 PST 2022
LegalizeAdulthood created this revision.
LegalizeAdulthood added reviewers: alexfh, njames93, aaron.ballman, JonasToth.
LegalizeAdulthood added a project: clang-tools-extra.
Herald added subscribers: carlosgalvezp, xazax.hun, mgorny.
LegalizeAdulthood requested review of this revision.
This check performs basic analysis of macros and replaces them
with an anonymous unscoped enum. Using an unscoped anonymous enum
ensures that everywhere the macro token was used previously, the
enumerator name may be safely used.
Potential macros for replacement must meet the following constraints:
- Macros must expand only to integral literal tokens.
- Macros must be defined on sequential source file lines, or with only comment lines in between macro definitions.
- Macros must all be defined in the same source file.
- Macros must not be defined within a conditional compilation block.
- Macros must not be defined adjacent to other preprocessor directives.
Each cluster of macros meeting the above constraints is presumed to
be a set of values suitable for replacement by an anonymous enum.
>From there, a developer can give the anonymous enum a name and
continue refactoring to a scoped enum if desired. Comments on the
same line as a macro definition or between subsequent macro definitions
are preserved in the output. No formatting is assumed in the provided
rG LLVM Github Monorepo
-------------- next part --------------
A non-text attachment was scrubbed...
Size: 23399 bytes
Desc: not available
More information about the cfe-commits