]> granicus.if.org Git - clang/commitdiff
Include types when a definition's type differs from a prior declaration.
authorDavid Blaikie <dblaikie@gmail.com>
Thu, 20 Sep 2012 18:38:57 +0000 (18:38 +0000)
committerDavid Blaikie <dblaikie@gmail.com>
Thu, 20 Sep 2012 18:38:57 +0000 (18:38 +0000)
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

include/clang/Basic/DiagnosticSemaKinds.td
lib/Sema/SemaDecl.cpp
test/Sema/types.c

index 038ebacbfbd281fd1071d153836f0eae92162784..637c5a509ffaf3fa8f2453ae4e095077ff8574ed 100644 (file)
@@ -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<
index 2dd5df1ea01fd4745b69d0b66052b9bc143c52f4..cbc3469fc773b6bd0dfb1677f9dbbdd50003af93 100644 (file)
@@ -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();
   }
index 3bec83e528b2d7cfd940acad6019d491a3766f79..6ae1a92e0543e81b710e3f3cdc59e570bb419385 100644 (file)
@@ -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}}