Produce a nice error message for '#define and' in C++.  Patch by Bill!

llvm-svn: 39218
diff --git a/clang/Lex/Preprocessor.cpp b/clang/Lex/Preprocessor.cpp
index 8facc3cc..e99f34e 100644
--- a/clang/Lex/Preprocessor.cpp
+++ b/clang/Lex/Preprocessor.cpp
@@ -1067,6 +1067,13 @@
   } while (Tmp.getKind() != tok::eom);
 }
 
+/// isCXXNamedOperator - Returns "true" if the token is a named operator in C++.
+static bool isCXXNamedOperator(const std::string &Spelling) {
+  return Spelling == "and" || Spelling == "bitand" || Spelling == "bitor" ||
+    Spelling == "compl" || Spelling == "not" || Spelling == "not_eq" ||
+    Spelling == "or" || Spelling == "xor";
+}
+
 /// ReadMacroName - Lex and validate a macro name, which occurs after a
 /// #define or #undef.  This sets the token kind to eom and discards the rest
 /// of the macro line if the macro name is invalid.  isDefineUndef is 1 if
@@ -1082,11 +1089,14 @@
   
   IdentifierInfo *II = MacroNameTok.getIdentifierInfo();
   if (II == 0) {
-    Diag(MacroNameTok, diag::err_pp_macro_not_identifier);
+    std::string Spelling = getSpelling(MacroNameTok);
+    if (isCXXNamedOperator(Spelling))
+      // C++ 2.5p2: Alternative tokens behave the same as its primary token
+      // except for their spellings.
+      Diag(MacroNameTok, diag::err_pp_operator_used_as_macro_name, Spelling);
+    else
+      Diag(MacroNameTok, diag::err_pp_macro_not_identifier);
     // Fall through on error.
-  } else if (0) {
-    // FIXME: C++.  Error if defining a C++ named operator.
-    
   } else if (isDefineUndef && II->getPPKeywordID() == tok::pp_defined) {
     // Error if defining "defined": C99 6.10.8.4.
     Diag(MacroNameTok, diag::err_defined_macro_name);