Skip to content
Merged
Show file tree
Hide file tree
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
8 changes: 6 additions & 2 deletions clang/lib/Lex/PPDirectives.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -371,8 +371,12 @@ bool Preprocessor::CheckMacroName(Token &MacroNameTok, MacroUse isDefineUndef,
SourceLocation MacroNameLoc = MacroNameTok.getLocation();
if (ShadowFlag)
*ShadowFlag = false;
if (!SourceMgr.isInSystemHeader(MacroNameLoc) &&
(SourceMgr.getBufferName(MacroNameLoc) != "<built-in>")) {
// 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).
bool IsBuiltinOrCmd = SourceMgr.isWrittenInBuiltinFile(MacroNameLoc) ||
SourceMgr.isWrittenInCommandLineFile(MacroNameLoc);
Copy link
Contributor

Choose a reason for hiding this comment

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

Can at least combine these to avoid the duplicate getPresumedLoc(), but possibly these can be more efficient in general? E.g. isInSystemHeader has a much more optimized implementation.

if (!IsBuiltinOrCmd && !SourceMgr.isInSystemHeader(MacroNameLoc)) {
MacroDiag D = MD_NoWarn;
if (isDefineUndef == MU_Define) {
D = shouldWarnOnMacroDef(*this, II);
Expand Down
11 changes: 11 additions & 0 deletions clang/test/Preprocessor/macro_reserved.i
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// RUN: %clang_cc1 -fsyntax-only -verify -x cpp-output %s
#pragma clang diagnostic push
#pragma clang diagnostic warning "-Wreserved-macro-identifier"
# 1 "<built-in>" 1
#define __BUILTIN__
# 2 "<command line>" 1
#define __CMD__
# 3 "biz.cpp" 1
#define __SOME_FILE__ // expected-warning {{macro name is a reserved identifier}}
int v;
#pragma clang diagnostic pop
Loading