1111// /
1212// ===----------------------------------------------------------------------===//
1313
14+ #include " clang/Basic/AttributeCommonInfo.h"
15+ #include " clang/Basic/Attributes.h"
1416#include " clang/Basic/CharInfo.h"
1517#include " clang/Basic/DirectoryEntry.h"
1618#include " clang/Basic/FileManager.h"
@@ -101,7 +103,8 @@ SourceRange Preprocessor::DiscardUntilEndOfDirective(Token &Tmp) {
101103enum MacroDiag {
102104 MD_NoWarn, // > Not a reserved identifier
103105 MD_KeywordDef, // > Macro hides keyword, enabled by default
104- MD_ReservedMacro // > #define of #undef reserved id, disabled by default
106+ MD_ReservedMacro, // > #define of #undef reserved id, disabled by default
107+ MD_ReservedAttributeIdentifier
105108};
106109
107110// / Enumerates possible %select values for the pp_err_elif_after_else and
@@ -177,6 +180,13 @@ static bool isLanguageDefinedBuiltin(const SourceManager &SourceMgr,
177180 return false ;
178181}
179182
183+ static bool isReservedCXXAttributeName (Preprocessor &PP, IdentifierInfo *II) {
184+ const LangOptions &Lang = PP.getLangOpts ();
185+ return Lang.CPlusPlus &&
186+ hasAttribute (AttributeCommonInfo::Syntax::AS_CXX11, /* Scope*/ nullptr ,
187+ II, PP.getTargetInfo (), Lang) > 0 ;
188+ }
189+
180190static MacroDiag shouldWarnOnMacroDef (Preprocessor &PP, IdentifierInfo *II) {
181191 const LangOptions &Lang = PP.getLangOpts ();
182192 StringRef Text = II->getName ();
@@ -186,6 +196,8 @@ static MacroDiag shouldWarnOnMacroDef(Preprocessor &PP, IdentifierInfo *II) {
186196 return MD_KeywordDef;
187197 if (Lang.CPlusPlus11 && (Text == " override" || Text == " final" ))
188198 return MD_KeywordDef;
199+ if (isReservedCXXAttributeName (PP, II))
200+ return MD_ReservedAttributeIdentifier;
189201 return MD_NoWarn;
190202}
191203
@@ -194,6 +206,8 @@ static MacroDiag shouldWarnOnMacroUndef(Preprocessor &PP, IdentifierInfo *II) {
194206 // Do not warn on keyword undef. It is generally harmless and widely used.
195207 if (isReservedInAllContexts (II->isReserved (Lang)))
196208 return MD_ReservedMacro;
209+ if (isReservedCXXAttributeName (PP, II))
210+ return MD_ReservedAttributeIdentifier;
197211 return MD_NoWarn;
198212}
199213
@@ -369,6 +383,9 @@ bool Preprocessor::CheckMacroName(Token &MacroNameTok, MacroUse isDefineUndef,
369383 }
370384 if (D == MD_ReservedMacro)
371385 Diag (MacroNameTok, diag::warn_pp_macro_is_reserved_id);
386+ if (D == MD_ReservedAttributeIdentifier)
387+ Diag (MacroNameTok, diag::warn_pp_macro_is_reserved_attribute_id)
388+ << II->getName ();
372389 }
373390
374391 // Okay, we got a good identifier.
0 commit comments