[cfe-commits] r39302 - in /cfe/cfe/trunk: AST/SemaDecl.cpp Sema/SemaDecl.cpp include/clang/AST/Decl.h include/clang/Basic/DiagnosticKinds.def
sabre at cs.uiuc.edu
sabre at cs.uiuc.edu
Wed Jul 11 09:42:45 PDT 2007
Author: sabre
Date: Wed Jul 11 11:42:44 2007
New Revision: 39302
URL: http://llvm.org/viewvc/llvm-project?rev=39302&view=rev
Log:
Register enumconstantdecls in their appropriate scope and check for conflicts.
This emits these diagnostics:
t.c:4:14: error: redefinition of 'a'
enum foo22 { a, b };
^
t.c:3:5: error: previous definition is here
int a;
^
t.c:8:17: error: redefinition of enumerator 'b'
enum foo23 { c, b };
^
t.c:4:17: error: previous definition is here
enum foo22 { a, b };
^
4 diagnostics generated.
for:
int a;
enum foo22 { a, b };
enum foo23 { c, b };
Modified:
cfe/cfe/trunk/AST/SemaDecl.cpp
cfe/cfe/trunk/Sema/SemaDecl.cpp
cfe/cfe/trunk/include/clang/AST/Decl.h
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=39302&r1=39301&r2=39302&view=diff
==============================================================================
--- cfe/cfe/trunk/AST/SemaDecl.cpp (original)
+++ cfe/cfe/trunk/AST/SemaDecl.cpp Wed Jul 11 11:42:44 2007
@@ -480,8 +480,29 @@
SourceLocation IdLoc, IdentifierInfo *Id,
SourceLocation EqualLoc, ExprTy *Val) {
EnumDecl *TheEnumDecl = cast<EnumDecl>(static_cast<Decl*>(EnumDeclX));
+
+ // Verify that there isn't already something declared with this name in this
+ // scope.
+ if (Decl *PrevDecl = LookupScopedDecl(Id, Decl::IDNS_Ordinary)) {
+ if (S->isDeclScope(PrevDecl)) {
+ if (isa<EnumConstantDecl>(PrevDecl))
+ Diag(IdLoc, diag::err_redefinition_of_enumerator, Id->getName());
+ else
+ Diag(IdLoc, diag::err_redefinition, Id->getName());
+ Diag(PrevDecl->getLocation(), diag::err_previous_definition);
+ return 0;
+ }
+ }
+
+
TypeRef Ty = Context.getTagDeclType(TheEnumDecl);
- return new EnumConstantDecl(IdLoc, Id, Ty);
+ EnumConstantDecl *New = new EnumConstantDecl(IdLoc, Id, Ty);
+
+ // Register this decl in the current scope stack.
+ New->setNext(Id->getFETokenInfo<Decl>());
+ Id->setFETokenInfo(New);
+ S->AddDecl(New);
+ return New;
}
void Sema::ParseEnumBody(SourceLocation EnumLoc, DeclTy *EnumDeclX,
Modified: cfe/cfe/trunk/Sema/SemaDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/cfe/trunk/Sema/SemaDecl.cpp?rev=39302&r1=39301&r2=39302&view=diff
==============================================================================
--- cfe/cfe/trunk/Sema/SemaDecl.cpp (original)
+++ cfe/cfe/trunk/Sema/SemaDecl.cpp Wed Jul 11 11:42:44 2007
@@ -480,8 +480,29 @@
SourceLocation IdLoc, IdentifierInfo *Id,
SourceLocation EqualLoc, ExprTy *Val) {
EnumDecl *TheEnumDecl = cast<EnumDecl>(static_cast<Decl*>(EnumDeclX));
+
+ // Verify that there isn't already something declared with this name in this
+ // scope.
+ if (Decl *PrevDecl = LookupScopedDecl(Id, Decl::IDNS_Ordinary)) {
+ if (S->isDeclScope(PrevDecl)) {
+ if (isa<EnumConstantDecl>(PrevDecl))
+ Diag(IdLoc, diag::err_redefinition_of_enumerator, Id->getName());
+ else
+ Diag(IdLoc, diag::err_redefinition, Id->getName());
+ Diag(PrevDecl->getLocation(), diag::err_previous_definition);
+ return 0;
+ }
+ }
+
+
TypeRef Ty = Context.getTagDeclType(TheEnumDecl);
- return new EnumConstantDecl(IdLoc, Id, Ty);
+ EnumConstantDecl *New = new EnumConstantDecl(IdLoc, Id, Ty);
+
+ // Register this decl in the current scope stack.
+ New->setNext(Id->getFETokenInfo<Decl>());
+ Id->setFETokenInfo(New);
+ S->AddDecl(New);
+ return New;
}
void Sema::ParseEnumBody(SourceLocation EnumLoc, DeclTy *EnumDeclX,
Modified: cfe/cfe/trunk/include/clang/AST/Decl.h
URL: http://llvm.org/viewvc/llvm-project/cfe/cfe/trunk/include/clang/AST/Decl.h?rev=39302&r1=39301&r2=39302&view=diff
==============================================================================
--- cfe/cfe/trunk/include/clang/AST/Decl.h (original)
+++ cfe/cfe/trunk/include/clang/AST/Decl.h Wed Jul 11 11:42:44 2007
@@ -79,6 +79,7 @@
case Typedef:
case Function:
case Variable:
+ case EnumConstant:
return IDNS_Ordinary;
case Struct:
case Union:
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=39302&r1=39301&r2=39302&view=diff
==============================================================================
--- cfe/cfe/trunk/include/clang/Basic/DiagnosticKinds.def (original)
+++ cfe/cfe/trunk/include/clang/Basic/DiagnosticKinds.def Wed Jul 11 11:42:44 2007
@@ -433,6 +433,8 @@
"use of '%s' with tag type that does not match previous declaration")
DIAG(ext_forward_ref_enum, EXTENSION,
"ISO C forbids forward references to 'enum' types")
+DIAG(err_redefinition_of_enumerator, ERROR,
+ "redefinition of enumerator '%s'")
DIAG(warn_implicit_function_decl, WARNING,
"implicit declaration of function '%s'")
More information about the cfe-commits
mailing list