From: Chris Lattner Date: Mon, 27 Apr 2009 01:46:12 +0000 (+0000) Subject: Change our silencing of C typedef redefinition handling to what we had X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=d0359af5113c1936ff3f699c7d700adff59351f2;p=clang 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. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@70177 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/clang/Basic/DiagnosticSemaKinds.td b/include/clang/Basic/DiagnosticSemaKinds.td index 448f16b0b8..7225aadbbc 100644 --- a/include/clang/Basic/DiagnosticSemaKinds.td +++ b/include/clang/Basic/DiagnosticSemaKinds.td @@ -740,9 +740,9 @@ def warn_missing_prototype : Warning< InGroup>, 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 >; + InGroup >, DefaultError; def err_static_non_static : Error< "static declaration of %0 follows non-static declaration">; diff --git a/lib/Sema/SemaDecl.cpp b/lib/Sema/SemaDecl.cpp index 1ea3a9ec3c..482c304603 100644 --- a/lib/Sema/SemaDecl.cpp +++ b/lib/Sema/SemaDecl.cpp @@ -560,7 +560,12 @@ void Sema::MergeTypeDefDecl(TypedefDecl *New, Decl *OldD) { // 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); diff --git a/test/Preprocessor/line-directive.c b/test/Preprocessor/line-directive.c index 53e9ab7b5d..ed9a6c40e5 100644 --- a/test/Preprocessor/line-directive.c +++ b/test/Preprocessor/line-directive.c @@ -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 @@ typedef int z1; // ok # 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.