[cfe-commits] r46070 - in /cfe/trunk: Sema/SemaDecl.cpp include/clang/Basic/DiagnosticKinds.def test/Sema/merge-decls.c test/Sema/predefined-function.c

Steve Naroff snaroff at apple.com
Wed Jan 16 07:01:38 PST 2008


Author: snaroff
Date: Wed Jan 16 09:01:34 2008
New Revision: 46070

URL: http://llvm.org/viewvc/llvm-project?rev=46070&view=rev
Log:

Sema::MergeFunctionDecl()...make sure diagnostic is accurate (wrt function declarations/definitions). Patch by Carl Lewis!


Modified:
    cfe/trunk/Sema/SemaDecl.cpp
    cfe/trunk/include/clang/Basic/DiagnosticKinds.def
    cfe/trunk/test/Sema/merge-decls.c
    cfe/trunk/test/Sema/predefined-function.c

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

==============================================================================
--- cfe/trunk/Sema/SemaDecl.cpp (original)
+++ cfe/trunk/Sema/SemaDecl.cpp Wed Jan 16 09:01:34 2008
@@ -251,11 +251,16 @@
   if (Context.functionTypesAreCompatible(OldQType, NewQType))
     return New;
 
+  // A function that has already been declared has been redeclared or defined
+  // with a different type- show appropriate diagnostic
+  diag::kind PrevDiag = Old->getBody() ? diag::err_previous_definition :
+                                         diag::err_previous_declaration; 
+
   // TODO: CHECK FOR CONFLICTS, multiple decls with same name in one scope.
   // TODO: This is totally simplistic.  It should handle merging functions
   // together etc, merging extern int X; int X; ...
-  Diag(New->getLocation(), diag::err_redefinition, New->getName());
-  Diag(Old->getLocation(), diag::err_previous_definition);
+  Diag(New->getLocation(), diag::err_conflicting_types, New->getName());
+  Diag(Old->getLocation(), PrevDiag);
   return New;
 }
 

Modified: cfe/trunk/include/clang/Basic/DiagnosticKinds.def
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticKinds.def?rev=46070&r1=46069&r2=46070&view=diff

==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticKinds.def (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticKinds.def Wed Jan 16 09:01:34 2008
@@ -598,6 +598,8 @@
      "redefinition of '%0'")
 DIAG(err_redefinition_different_kind, ERROR,
      "redefinition of '%0' as different kind of symbol")
+DIAG(err_conflicting_types, ERROR,
+     "conflicting types for '%0'")
 DIAG(err_nested_redefinition, ERROR,
      "nested redefinition of '%0'")
 DIAG(err_use_with_wrong_tag, ERROR,

Modified: cfe/trunk/test/Sema/merge-decls.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/merge-decls.c?rev=46070&r1=46069&r2=46070&view=diff

==============================================================================
--- cfe/trunk/test/Sema/merge-decls.c (original)
+++ cfe/trunk/test/Sema/merge-decls.c Wed Jan 16 09:01:34 2008
@@ -3,9 +3,9 @@
 void foo(void);
 void foo(void) {} 
 void foo(void);
-void foo(void); // expected-error{{previous definition is here}}
+void foo(void); // expected-error{{previous declaration is here}}
 
-void foo(int); // expected-error {{redefinition of 'foo'}}
+void foo(int); // expected-error {{conflicting types for 'foo'}}
 
 int funcdef()
 {

Modified: cfe/trunk/test/Sema/predefined-function.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/predefined-function.c?rev=46070&r1=46069&r2=46070&view=diff

==============================================================================
--- cfe/trunk/test/Sema/predefined-function.c (original)
+++ cfe/trunk/test/Sema/predefined-function.c Wed Jan 16 09:01:34 2008
@@ -4,13 +4,13 @@
 enum Test {A=-1};
 char *funk(enum Test x);
 
-int eli(float b); // expected-error {{previous definition is here}}
+int eli(float b); // expected-error {{previous declaration is here}}
 int b(int c) {return 1;}
 
 int foo();
 int foo()
 {
-    int eli(int (int)); // expected-error {{redefinition of 'eli'}}
+    int eli(int (int)); // expected-error {{conflicting types for 'eli'}}
     eli(b);
 	return 0;	
 }
@@ -20,19 +20,19 @@
 {
 	return 0;
 }
-int bar() // expected-error {{redefinition of 'bar'}}
+int bar() // expected-error {{redefinition of 'bar'}} expected-error {{conflicting types for 'bar'}}
 {
 	return 0;
 }
 
-int foobar(int); // expected-error {{previous definition is here}}
-int foobar() // expected-error {{redefinition of 'foobar'}}
+int foobar(int); // expected-error {{previous declaration is here}}
+int foobar() // expected-error {{conflicting types for 'foobar'}}
 {
 	return 0;
 }
 
-int wibble(); // expected-error {{previous definition is here}}
-float wibble() // expected-error {{redefinition of 'wibble'}}
+int wibble(); // expected-error {{previous declaration is here}}
+float wibble() // expected-error {{conflicting types for 'wibble'}}
 {
 	return 0.0f;
 }





More information about the cfe-commits mailing list