[cfe-commits] r38678 - in /cfe/cfe/trunk: Lex/Preprocessor.cpp include/clang/Basic/DiagnosticKinds.def include/clang/Lex/Preprocessor.h

sabre at cs.uiuc.edu sabre at cs.uiuc.edu
Wed Jul 11 09:23:44 PDT 2007


Author: sabre
Date: Wed Jul 11 11:23:44 2007
New Revision: 38678

URL: http://llvm.org/viewvc/llvm-project?rev=38678&view=rev
Log:
Warn about __VA_ARGS__ when used outside of a macro expansion

Modified:
    cfe/cfe/trunk/Lex/Preprocessor.cpp
    cfe/cfe/trunk/include/clang/Basic/DiagnosticKinds.def
    cfe/cfe/trunk/include/clang/Lex/Preprocessor.h

Modified: cfe/cfe/trunk/Lex/Preprocessor.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/cfe/trunk/Lex/Preprocessor.cpp?rev=38678&r1=38677&r2=38678&view=diff

==============================================================================
--- cfe/cfe/trunk/Lex/Preprocessor.cpp (original)
+++ cfe/cfe/trunk/Lex/Preprocessor.cpp Wed Jul 11 11:23:44 2007
@@ -67,6 +67,10 @@
   FileChangeHandler = 0;
   IdentHandler = 0;
   
+  // "Poison" __VA_ARGS__, which can only appear in the expansion of a macro.
+  // This gets unpoisoned where it is allowed.
+  (Ident__VA_ARGS__ = getIdentifierInfo("__VA_ARGS__"))->setIsPoisoned();
+  
   // Initialize the pragma handlers.
   PragmaHandlers = new PragmaNamespace(0);
   RegisterBuiltinPragmas();
@@ -716,8 +720,12 @@
 
   // If this identifier was poisoned, and if it was not produced from a macro
   // expansion, emit an error.
-  if (II.isPoisoned() && CurLexer)
-    Diag(Identifier, diag::err_pp_used_poisoned_id);
+  if (II.isPoisoned() && CurLexer) {
+    if (&II != Ident__VA_ARGS__)   // We warn about __VA_ARGS__ with poisoning.
+      Diag(Identifier, diag::err_pp_used_poisoned_id);
+    else
+      Diag(Identifier, diag::ext_pp_bad_vaargs_use);
+  }
   
   if (MacroInfo *MI = II.getMacroInfo())
     if (MI->isEnabled() && !DisableMacroExpansion)

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=38678&r1=38677&r2=38678&view=diff

==============================================================================
--- cfe/cfe/trunk/include/clang/Basic/DiagnosticKinds.def (original)
+++ cfe/cfe/trunk/include/clang/Basic/DiagnosticKinds.def Wed Jul 11 11:23:44 2007
@@ -61,7 +61,7 @@
      "'$' in identifier")
 
 DIAG(ext_token_used, EXTENSION,
-     "Extension used")
+     "extension used")
 
 DIAG(err_unterminated_string, ERROR,
      "missing terminating \" character")
@@ -113,6 +113,8 @@
      "extra tokens at end of %s directive")
 DIAG(ext_pp_comma_expr, EXTENSION,
      "comma operator in operand of #if")
+DIAG(ext_pp_bad_vaargs_use, EXTENSION,
+     "__VA_ARGS__ can only appear in the expansion of a C99 variadic macro")
      
 DIAG(ext_pp_base_file, EXTENSION,
      "__BASE_FILE__ is a language extension")

Modified: cfe/cfe/trunk/include/clang/Lex/Preprocessor.h
URL: http://llvm.org/viewvc/llvm-project/cfe/cfe/trunk/include/clang/Lex/Preprocessor.h?rev=38678&r1=38677&r2=38678&view=diff

==============================================================================
--- cfe/cfe/trunk/include/clang/Lex/Preprocessor.h (original)
+++ cfe/cfe/trunk/include/clang/Lex/Preprocessor.h Wed Jul 11 11:23:44 2007
@@ -92,13 +92,13 @@
   unsigned SystemDirIdx;
   bool NoCurDirSearch;
   
-  /// Identifiers for builtin macros.
-  IdentifierInfo *Ident__LINE__, *Ident__FILE__; // __LINE__, __FILE__
-  IdentifierInfo *Ident__DATE__, *Ident__TIME__; // __DATE__, __TIME__
-  IdentifierInfo *Ident__INCLUDE_LEVEL__;        // __INCLUDE_LEVEL__
-  IdentifierInfo *Ident__BASE_FILE__;            // __BASE_FILE__
-  IdentifierInfo *Ident__TIMESTAMP__;            // __TIMESTAMP__
-  IdentifierInfo *Ident_Pragma;                  // _Pragma
+  /// Identifiers for builtin macros and other builtins.
+  IdentifierInfo *Ident__LINE__, *Ident__FILE__;   // __LINE__, __FILE__
+  IdentifierInfo *Ident__DATE__, *Ident__TIME__;   // __DATE__, __TIME__
+  IdentifierInfo *Ident__INCLUDE_LEVEL__;          // __INCLUDE_LEVEL__
+  IdentifierInfo *Ident__BASE_FILE__;              // __BASE_FILE__
+  IdentifierInfo *Ident__TIMESTAMP__;              // __TIMESTAMP__
+  IdentifierInfo *Ident_Pragma, *Ident__VA_ARGS__; // _Pragma, __VA_ARGS__
   
   SourceLocation DATELoc, TIMELoc;
 public:





More information about the cfe-commits mailing list