[cfe-commits] r39323 - in /cfe/cfe/trunk: AST/SemaDecl.cpp Sema/SemaDecl.cpp include/clang/Basic/DiagnosticKinds.def

sabre at cs.uiuc.edu sabre at cs.uiuc.edu
Wed Jul 11 09:43:05 PDT 2007


Author: sabre
Date: Wed Jul 11 11:43:05 2007
New Revision: 39323

URL: http://llvm.org/viewvc/llvm-project?rev=39323&view=rev
Log:
Add some better diagnostics for things like:
int foo;
int foo();

Modified:
    cfe/cfe/trunk/AST/SemaDecl.cpp
    cfe/cfe/trunk/Sema/SemaDecl.cpp
    cfe/cfe/trunk/include/clang/Basic/DiagnosticKinds.def

Modified: cfe/cfe/trunk/AST/SemaDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/cfe/trunk/AST/SemaDecl.cpp?rev=39323&r1=39322&r2=39323&view=diff

==============================================================================
--- cfe/cfe/trunk/AST/SemaDecl.cpp (original)
+++ cfe/cfe/trunk/AST/SemaDecl.cpp Wed Jul 11 11:43:05 2007
@@ -95,7 +95,16 @@
 /// and scope as a previous declaration 'Old'.  Figure out how to resolve this
 /// situation, merging decls or emitting diagnostics as appropriate.
 ///
-TypedefDecl *Sema::MergeTypeDefDecl(TypedefDecl *New, Decl *Old) {
+TypedefDecl *Sema::MergeTypeDefDecl(TypedefDecl *New, Decl *OldD) {
+  // Verify the old decl was also a typedef.
+  TypedefDecl *Old = dyn_cast<TypedefDecl>(OldD);
+  if (!Old) {
+    Diag(New->getLocation(), diag::err_redefinition_different_kind,
+         New->getName());
+    Diag(OldD->getLocation(), diag::err_previous_definition);
+    return New;
+  }
+  
   // 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; ...
@@ -108,7 +117,19 @@
 /// and scope as a previous declaration 'Old'.  Figure out how to resolve this
 /// situation, merging decls or emitting diagnostics as appropriate.
 ///
-FunctionDecl *Sema::MergeFunctionDecl(FunctionDecl *New, Decl *Old) {
+FunctionDecl *Sema::MergeFunctionDecl(FunctionDecl *New, Decl *OldD) {
+  // Verify the old decl was also a function.
+  FunctionDecl *Old = dyn_cast<FunctionDecl>(OldD);
+  if (!Old) {
+    Diag(New->getLocation(), diag::err_redefinition_different_kind,
+         New->getName());
+    Diag(OldD->getLocation(), diag::err_previous_definition);
+    return New;
+  }
+  
+  // This is not right, but it's a start.  If 'Old' is a 
+  
+  
   // 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; ...
@@ -121,7 +142,16 @@
 /// and scope as a previous declaration 'Old'.  Figure out how to resolve this
 /// situation, merging decls or emitting diagnostics as appropriate.
 ///
-VarDecl *Sema::MergeVarDecl(VarDecl *New, Decl *Old) {
+VarDecl *Sema::MergeVarDecl(VarDecl *New, Decl *OldD) {
+  // Verify the old decl was also a variable.
+  VarDecl *Old = dyn_cast<VarDecl>(OldD);
+  if (!Old) {
+    Diag(New->getLocation(), diag::err_redefinition_different_kind,
+         New->getName());
+    Diag(OldD->getLocation(), diag::err_previous_definition);
+    return New;
+  }
+  
   // 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; ...

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

==============================================================================
--- cfe/cfe/trunk/Sema/SemaDecl.cpp (original)
+++ cfe/cfe/trunk/Sema/SemaDecl.cpp Wed Jul 11 11:43:05 2007
@@ -95,7 +95,16 @@
 /// and scope as a previous declaration 'Old'.  Figure out how to resolve this
 /// situation, merging decls or emitting diagnostics as appropriate.
 ///
-TypedefDecl *Sema::MergeTypeDefDecl(TypedefDecl *New, Decl *Old) {
+TypedefDecl *Sema::MergeTypeDefDecl(TypedefDecl *New, Decl *OldD) {
+  // Verify the old decl was also a typedef.
+  TypedefDecl *Old = dyn_cast<TypedefDecl>(OldD);
+  if (!Old) {
+    Diag(New->getLocation(), diag::err_redefinition_different_kind,
+         New->getName());
+    Diag(OldD->getLocation(), diag::err_previous_definition);
+    return New;
+  }
+  
   // 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; ...
@@ -108,7 +117,19 @@
 /// and scope as a previous declaration 'Old'.  Figure out how to resolve this
 /// situation, merging decls or emitting diagnostics as appropriate.
 ///
-FunctionDecl *Sema::MergeFunctionDecl(FunctionDecl *New, Decl *Old) {
+FunctionDecl *Sema::MergeFunctionDecl(FunctionDecl *New, Decl *OldD) {
+  // Verify the old decl was also a function.
+  FunctionDecl *Old = dyn_cast<FunctionDecl>(OldD);
+  if (!Old) {
+    Diag(New->getLocation(), diag::err_redefinition_different_kind,
+         New->getName());
+    Diag(OldD->getLocation(), diag::err_previous_definition);
+    return New;
+  }
+  
+  // This is not right, but it's a start.  If 'Old' is a 
+  
+  
   // 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; ...
@@ -121,7 +142,16 @@
 /// and scope as a previous declaration 'Old'.  Figure out how to resolve this
 /// situation, merging decls or emitting diagnostics as appropriate.
 ///
-VarDecl *Sema::MergeVarDecl(VarDecl *New, Decl *Old) {
+VarDecl *Sema::MergeVarDecl(VarDecl *New, Decl *OldD) {
+  // Verify the old decl was also a variable.
+  VarDecl *Old = dyn_cast<VarDecl>(OldD);
+  if (!Old) {
+    Diag(New->getLocation(), diag::err_redefinition_different_kind,
+         New->getName());
+    Diag(OldD->getLocation(), diag::err_previous_definition);
+    return New;
+  }
+  
   // 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; ...

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

==============================================================================
--- cfe/cfe/trunk/include/clang/Basic/DiagnosticKinds.def (original)
+++ cfe/cfe/trunk/include/clang/Basic/DiagnosticKinds.def Wed Jul 11 11:43:05 2007
@@ -427,6 +427,8 @@
      "use of undeclared identifier '%s'")
 DIAG(err_redefinition, ERROR,
      "redefinition of '%s'")
+DIAG(err_redefinition_different_kind, ERROR,
+     "redefinition of '%s' as different kind of symbol")
 DIAG(err_nested_redefinition, ERROR,
      "nested redefinition of '%s'")
 DIAG(err_use_with_wrong_tag, ERROR,





More information about the cfe-commits mailing list