summaryrefslogtreecommitdiffstats
path: root/clang/lib/Lex/PPDirectives.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'clang/lib/Lex/PPDirectives.cpp')
-rw-r--r--clang/lib/Lex/PPDirectives.cpp55
1 files changed, 5 insertions, 50 deletions
diff --git a/clang/lib/Lex/PPDirectives.cpp b/clang/lib/Lex/PPDirectives.cpp
index e359ea5ec39..7add52661a6 100644
--- a/clang/lib/Lex/PPDirectives.cpp
+++ b/clang/lib/Lex/PPDirectives.cpp
@@ -100,53 +100,15 @@ void Preprocessor::DiscardUntilEndOfDirective() {
} while (Tmp.isNot(tok::eod));
}
-/// \brief Enumerates possible cases of #define/#undef a reserved identifier.
-enum MacroDiag {
- MD_NoWarn, //> Not a reserved identifier
- MD_KeywordDef, //> Macro hides keyword, enabled by default
- MD_ReservedMacro //> #define of #undef reserved id, disabled by default
-};
-
-/// \brief Checks if the specified identifier is reserved in the specified
-/// language.
-/// This function does not check if the identifier is a keyword.
-static bool isReservedId(StringRef Text, const LangOptions &Lang) {
- // C++ [macro.names], C11 7.1.3:
- // All identifiers that begin with an underscore and either an uppercase
- // letter or another underscore are always reserved for any use.
- if (Text.size() >= 2 && Text[0] == '_' &&
- (isUppercase(Text[1]) || Text[1] == '_'))
- return true;
- // C++ [global.names]
- // Each name that contains a double underscore ... is reserved to the
- // implementation for any use.
- if (Lang.CPlusPlus) {
- if (Text.find("__") != StringRef::npos)
- return true;
- }
- return false;
-}
-
-static MacroDiag shouldWarnOnMacroDef(Preprocessor &PP, IdentifierInfo *II) {
+static bool shouldWarnOnMacroDef(Preprocessor &PP, IdentifierInfo *II) {
const LangOptions &Lang = PP.getLangOpts();
StringRef Text = II->getName();
- if (isReservedId(Text, Lang))
- return MD_ReservedMacro;
// Do not warn on keyword undef. It is generally harmless and widely used.
if (II->isKeyword(Lang))
- return MD_KeywordDef;
+ return true;
if (Lang.CPlusPlus && (Text.equals("override") || Text.equals("final")))
- return MD_KeywordDef;
- return MD_NoWarn;
-}
-
-static MacroDiag shouldWarnOnMacroUndef(Preprocessor &PP, IdentifierInfo *II) {
- const LangOptions &Lang = PP.getLangOpts();
- StringRef Text = II->getName();
- // Do not warn on keyword undef. It is generally harmless and widely used.
- if (isReservedId(Text, Lang))
- return MD_ReservedMacro;
- return MD_NoWarn;
+ return true;
+ return false;
}
bool Preprocessor::CheckMacroName(Token &MacroNameTok, MacroUse isDefineUndef) {
@@ -193,15 +155,8 @@ bool Preprocessor::CheckMacroName(Token &MacroNameTok, MacroUse isDefineUndef) {
SourceLocation MacroNameLoc = MacroNameTok.getLocation();
if (!SourceMgr.isInSystemHeader(MacroNameLoc) &&
(strcmp(SourceMgr.getBufferName(MacroNameLoc), "<built-in>") != 0)) {
- MacroDiag D = MD_NoWarn;
- if (isDefineUndef == MU_Define)
- D = shouldWarnOnMacroDef(*this, II);
- else if (isDefineUndef == MU_Undef)
- D = shouldWarnOnMacroUndef(*this, II);
- if (D == MD_KeywordDef)
+ if (isDefineUndef == MU_Define && shouldWarnOnMacroDef(*this, II))
Diag(MacroNameTok, diag::warn_pp_macro_hides_keyword);
- if (D == MD_ReservedMacro)
- Diag(MacroNameTok, diag::warn_pp_macro_is_reserved_id);
}
// Okay, we got a good identifier.
OpenPOWER on IntegriCloud