[cfe-commits] r39218 - in /cfe/cfe/trunk: Lex/Preprocessor.cpp include/clang/Basic/DiagnosticKinds.def
sabre at cs.uiuc.edu
sabre at cs.uiuc.edu
Wed Jul 11 09:41:23 PDT 2007
Author: sabre
Date: Wed Jul 11 11:41:23 2007
New Revision: 39218
URL: http://llvm.org/viewvc/llvm-project?rev=39218&view=rev
Log:
Produce a nice error message for '#define and' in C++. Patch by Bill!
Modified:
cfe/cfe/trunk/Lex/Preprocessor.cpp
cfe/cfe/trunk/include/clang/Basic/DiagnosticKinds.def
Modified: cfe/cfe/trunk/Lex/Preprocessor.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/cfe/trunk/Lex/Preprocessor.cpp?rev=39218&r1=39217&r2=39218&view=diff
==============================================================================
--- cfe/cfe/trunk/Lex/Preprocessor.cpp (original)
+++ cfe/cfe/trunk/Lex/Preprocessor.cpp Wed Jul 11 11:41:23 2007
@@ -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);
Modified: cfe/cfe/trunk/include/clang/Basic/DiagnosticKinds.def
URL: http://llvm.org/viewvc/llvm-project/cfe/cfe/trunk/include/clang/Basic/DiagnosticKinds.def?rev=39218&r1=39217&r2=39218&view=diff
==============================================================================
--- cfe/cfe/trunk/include/clang/Basic/DiagnosticKinds.def (original)
+++ cfe/cfe/trunk/include/clang/Basic/DiagnosticKinds.def Wed Jul 11 11:41:23 2007
@@ -232,6 +232,8 @@
"too few arguments provided to function-like macro invocation")
DIAG(err_pp_bad_paste, ERROR,
"pasting formed \"%s\", an invalid preprocessing token")
+DIAG(err_pp_operator_used_as_macro_name, ERROR,
+ "C++ operator \"%s\" cannot be used as a macro name")
// Should be a sorry?
DIAG(err_pp_I_dash_not_supported, ERROR,
More information about the cfe-commits
mailing list