From: David Blaikie Date: Thu, 20 Sep 2012 18:38:57 +0000 (+0000) Subject: Include types when a definition's type differs from a prior declaration. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=a405b2523b8857e0ba7e6374648b14f618879f33;p=clang Include types when a definition's type differs from a prior declaration. This is some really old code (took me a while to find the test cases) & the diagnostic text is slightly incorrect (it should really only apply to re/declarations/, redefinitions are an error regardless of whether the types match). Not sure if anyone cares about it, though. For now this just makes the diagnostic more clear in less obvious cases where the type of a declaration might not be explicitly written (eg: because it uses decltype) git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@164313 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/clang/Basic/DiagnosticSemaKinds.td b/include/clang/Basic/DiagnosticSemaKinds.td index 038ebacbfb..637c5a509f 100644 --- a/include/clang/Basic/DiagnosticSemaKinds.td +++ b/include/clang/Basic/DiagnosticSemaKinds.td @@ -3185,7 +3185,7 @@ def err_non_thread_thread : Error< def err_thread_non_thread : Error< "thread-local declaration of %0 follows non-thread-local declaration">; def err_redefinition_different_type : Error< - "redefinition of %0 with a different type">; + "redefinition of %0 with a different type%diff{: $ vs $|}1,2">; def err_redefinition_different_kind : Error< "redefinition of %0 as different kind of symbol">; def warn_forward_class_redefinition : Warning< diff --git a/lib/Sema/SemaDecl.cpp b/lib/Sema/SemaDecl.cpp index 2dd5df1ea0..cbc3469fc7 100644 --- a/lib/Sema/SemaDecl.cpp +++ b/lib/Sema/SemaDecl.cpp @@ -2442,7 +2442,7 @@ void Sema::MergeVarDeclTypes(VarDecl *New, VarDecl *Old) { } if (MergedT.isNull()) { Diag(New->getLocation(), diag::err_redefinition_different_type) - << New->getDeclName(); + << New->getDeclName() << New->getType() << Old->getType(); Diag(Old->getLocation(), diag::note_previous_definition); return New->setInvalidDecl(); } diff --git a/test/Sema/types.c b/test/Sema/types.c index 3bec83e528..6ae1a92e05 100644 --- a/test/Sema/types.c +++ b/test/Sema/types.c @@ -43,7 +43,7 @@ int i[(short)1]; enum e { e_1 }; extern int j[sizeof(enum e)]; // expected-note {{previous definition}} -int j[42]; // expected-error {{redefinition of 'j' with a different type}} +int j[42]; // expected-error {{redefinition of 'j' with a different type: 'int [42]' vs 'int [4]'}} // rdar://6880104 _Decimal32 x; // expected-error {{GNU decimal type extension not supported}}