This is an archive of the discontinued LLVM Phabricator instance.

[clang-tidy] Modernize-macro-to-enum should skip macros used in other macros
ClosedPublic

Authored by LegalizeAdulthood on Apr 22 2022, 6:41 PM.

Details

Summary

If a macro is used in the expansion of another macro, that can cause
a compile error if the macro is replaced with an enum. Token-pasting is
an example where converting a macro defined as an integral constant can
cause code to no longer compile.

This change causes such macros to be skipped from the conversion
process in order to prevent fixits from creating code that no longer
compiles.

A subsequent enhancement will examine macro usage in more detail to
allow more cases to be handled without breaking code.

Fixes #54948

Diff Detail

Event Timeline

Herald added a project: Restricted Project. · View Herald TranscriptApr 22 2022, 6:41 PM
LegalizeAdulthood requested review of this revision.Apr 22 2022, 6:41 PM

Gentle ping.

I have another change based on this that fixes #55055
Enhance modernize-macro-to-enum to recognize constant literal expressions

aaron.ballman accepted this revision.Apr 26 2022, 8:09 AM

LGTM with a few small nits.

clang-tools-extra/clang-tidy/modernize/MacroToEnumCheck.cpp
230

ArrayRef is intended to be cheap in the same way as StringRef, so we don't pass const references for it.

316–318

I know the coding guide says we can elide braces there, but because the for loop substatement is multiple lines, I think braces help readability.

This revision is now accepted and ready to land.Apr 26 2022, 8:09 AM
LegalizeAdulthood marked 2 inline comments as done.Apr 26 2022, 7:13 PM

Update from review comments

This revision was landed with ongoing or failed builds.Apr 26 2022, 8:10 PM
This revision was automatically updated to reflect the committed changes.