[cfe-commits] r38625 - 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:23:19 PDT 2007


Author: sabre
Date: Wed Jul 11 11:23:19 2007
New Revision: 38625

URL: http://llvm.org/viewvc/llvm-project?rev=38625&view=rev
Log:
Implement a FIXME: reject '#define defined'.

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=38625&r1=38624&r2=38625&view=diff

==============================================================================
--- cfe/cfe/trunk/Lex/Preprocessor.cpp (original)
+++ cfe/cfe/trunk/Lex/Preprocessor.cpp Wed Jul 11 11:23:19 2007
@@ -817,14 +817,18 @@
   if (MacroNameTok.getKind() == tok::eom)
     return Diag(MacroNameTok, diag::err_pp_missing_macro_name);
   
-  if (MacroNameTok.getIdentifierInfo() == 0) {
+  IdentifierTokenInfo *ITI = MacroNameTok.getIdentifierInfo();
+  if (ITI == 0) {
     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 (0) {
-    // FIXME: Error if defining "defined" in C99 6.10.8.4.
+  } else if (ITI->getName()[0] == 'd' &&      // defined
+             !strcmp(ITI->getName()+1, "efined")) {
+    // Error if defining "defined": C99 6.10.8.4.  Predefined macros (like
+    // __LINE__) are handled in the undef/define handlers.
+    Diag(MacroNameTok, diag::err_defined_macro_name);
   } else {
     // Okay, we got a good identifier node.  Return it.
     return;

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=38625&r1=38624&r2=38625&view=diff

==============================================================================
--- cfe/cfe/trunk/include/clang/Basic/DiagnosticKinds.def (original)
+++ cfe/cfe/trunk/include/clang/Basic/DiagnosticKinds.def Wed Jul 11 11:23:19 2007
@@ -173,6 +173,8 @@
      "attempt to use a poisoned identifier")
 DIAG(err__Pragma_malformed, ERROR,
      "_Pragma takes a parenthesized string literal")
+DIAG(err_defined_macro_name, ERROR,
+     "\"defined\" 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