Skip to content

[clang][Lex][NFC] Reorder SrcMgr checks in CheckMacroName #141483

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 29, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions clang/lib/Lex/PPDirectives.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -373,8 +373,10 @@ bool Preprocessor::CheckMacroName(Token &MacroNameTok, MacroUse isDefineUndef,
// Macro names with reserved identifiers are accepted if built-in or passed
// through the command line (the later may be present if -dD was used to
// generate the preprocessed file).
if (!SourceMgr.isInPredefinedFile(MacroNameLoc) &&
!SourceMgr.isInSystemHeader(MacroNameLoc)) {
// NB: isInPredefinedFile() is relatively expensive, so keep it at the end
// of the condition.
if (!SourceMgr.isInSystemHeader(MacroNameLoc) &&
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems like change deserves a note since it is not obvious the order matters or why.

!SourceMgr.isInPredefinedFile(MacroNameLoc)) {
MacroDiag D = MD_NoWarn;
if (isDefineUndef == MU_Define) {
D = shouldWarnOnMacroDef(*this, II);
Expand Down
Loading