[cfe-commits] r70177 - in /cfe/trunk: include/clang/Basic/DiagnosticSemaKinds.td lib/Sema/SemaDecl.cpp test/Preprocessor/line-directive.c

Chris Lattner sabre at nondot.org
Sun Apr 26 18:46:12 PDT 2009


Author: lattner
Date: Sun Apr 26 20:46:12 2009
New Revision: 70177

URL: http://llvm.org/viewvc/llvm-project?rev=70177&view=rev
Log:
Change our silencing of C typedef redefinition handling to what we had
before r69391: typedef redefinition is an error by default, but if
*either* the old or new definition are from a system header, we silence
it.

Modified:
    cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
    cfe/trunk/lib/Sema/SemaDecl.cpp
    cfe/trunk/test/Preprocessor/line-directive.c

Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=70177&r1=70176&r2=70177&view=diff

==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Sun Apr 26 20:46:12 2009
@@ -740,9 +740,9 @@
   InGroup<DiagGroup<"missing-prototypes">>, DefaultIgnore;
 def err_redefinition : Error<"redefinition of %0">;
 
-def warn_redefinition_of_typedef : ExtWarn<
+def warn_redefinition_of_typedef : Warning<
   "redefinition of typedef %0 is invalid in C">,
-  InGroup<DiagGroup<"typedef-redefinition"> >;
+  InGroup<DiagGroup<"typedef-redefinition"> >, DefaultError;
 
 def err_static_non_static : Error<
   "static declaration of %0 follows non-static declaration">;

Modified: cfe/trunk/lib/Sema/SemaDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=70177&r1=70176&r2=70177&view=diff

==============================================================================
--- cfe/trunk/lib/Sema/SemaDecl.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDecl.cpp Sun Apr 26 20:46:12 2009
@@ -560,7 +560,12 @@
 
   // If we have a redefinition of a typedef in C, emit a warning.  This warning
   // is normally mapped to an error, but can be controlled with
-  // -Wtypedef-redefinition.
+  // -Wtypedef-redefinition.  If either the original was in a system header,
+  // don't emit this for compatibility with GCC.
+  if (PP.getDiagnostics().getSuppressSystemWarnings() &&
+      Context.getSourceManager().isInSystemHeader(Old->getLocation()))
+    return;
+  
   Diag(New->getLocation(), diag::warn_redefinition_of_typedef)
     << New->getDeclName();
   Diag(Old->getLocation(), diag::note_previous_definition);

Modified: cfe/trunk/test/Preprocessor/line-directive.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Preprocessor/line-directive.c?rev=70177&r1=70176&r2=70177&view=diff

==============================================================================
--- cfe/trunk/test/Preprocessor/line-directive.c (original)
+++ cfe/trunk/test/Preprocessor/line-directive.c Sun Apr 26 20:46:12 2009
@@ -41,12 +41,14 @@
 
 # 192 "glomp.h" // not a system header.
 typedef int x;  // expected-note {{previous definition is here}}
-typedef int x;  // expected-warning {{redefinition of typedef 'x' is invalid in C}}
+typedef int x;  // expected-error {{redefinition of typedef 'x' is invalid in C}}
 
 # 192 "glomp.h" 3 // System header.
 typedef int y;  // ok
 typedef int y;  // ok
 
+typedef int q;  // q is in system header.
+
 #line 42 "blonk.h"  // doesn't change system headerness.
 
 typedef int z;  // ok
@@ -60,8 +62,9 @@
 # 42 "blonk.h"  // DOES change system headerness.
 
 typedef int w;  // expected-note {{previous definition is here}}
-typedef int w;  // expected-warning {{redefinition of typedef 'w' is invalid in C}}
+typedef int w;  // expected-error {{redefinition of typedef 'w' is invalid in C}}
 
+typedef int q;  // original definition in system header, should not diagnose.
 
 // This should not produce an "extra tokens at end of #line directive" warning,
 // because #line is allowed to contain expanded tokens.





More information about the cfe-commits mailing list