[cfe-commits] r39303 - 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:42:46 PDT 2007
Author: sabre
Date: Wed Jul 11 11:42:45 2007
New Revision: 39303
URL: http://llvm.org/viewvc/llvm-project?rev=39303&view=rev
Log:
Reject:
struct q { int a, a; };
with:
t.c:3:19: error: duplicate member 'a'
struct q { int a, a; };
^
t.c:3:16: error: previous definition is here
struct q { int a, a; };
^
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=39303&r1=39302&r2=39303&view=diff
==============================================================================
--- cfe/cfe/trunk/AST/SemaDecl.cpp (original)
+++ cfe/cfe/trunk/AST/SemaDecl.cpp Wed Jul 11 11:42:45 2007
@@ -400,6 +400,8 @@
// Verify that all the fields are okay.
unsigned NumNamedMembers = 0;
SmallVector<Decl*, 32> RecFields;
+ SmallSet<const IdentifierInfo*, 32> FieldIDs;
+
for (unsigned i = 0; i != NumFields; ++i) {
FieldDecl *FD = cast_or_null<FieldDecl>(static_cast<Decl*>(Fields[i]));
if (!FD) continue; // Already issued a diagnostic.
@@ -464,8 +466,25 @@
}
// Keep track of the number of named members.
- if (FD->getIdentifier())
+ if (IdentifierInfo *II = FD->getIdentifier()) {
+ // Detect duplicate member names.
+ if (!FieldIDs.insert(II).second) {
+ Diag(FD->getLocation(), diag::err_duplicate_member, II->getName());
+ // Find the previous decl.
+ SourceLocation PrevLoc;
+ for (unsigned i = 0, e = RecFields.size(); ; ++i) {
+ assert(i != e && "Didn't find previous def!");
+ if (RecFields[i]->getIdentifier() == II) {
+ PrevLoc = RecFields[i]->getLocation();
+ break;
+ }
+ }
+ Diag(PrevLoc, diag::err_previous_definition);
+ delete FD;
+ continue;
+ }
++NumNamedMembers;
+ }
// Remember good fields.
RecFields.push_back(FD);
Modified: cfe/cfe/trunk/Sema/SemaDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/cfe/trunk/Sema/SemaDecl.cpp?rev=39303&r1=39302&r2=39303&view=diff
==============================================================================
--- cfe/cfe/trunk/Sema/SemaDecl.cpp (original)
+++ cfe/cfe/trunk/Sema/SemaDecl.cpp Wed Jul 11 11:42:45 2007
@@ -400,6 +400,8 @@
// Verify that all the fields are okay.
unsigned NumNamedMembers = 0;
SmallVector<Decl*, 32> RecFields;
+ SmallSet<const IdentifierInfo*, 32> FieldIDs;
+
for (unsigned i = 0; i != NumFields; ++i) {
FieldDecl *FD = cast_or_null<FieldDecl>(static_cast<Decl*>(Fields[i]));
if (!FD) continue; // Already issued a diagnostic.
@@ -464,8 +466,25 @@
}
// Keep track of the number of named members.
- if (FD->getIdentifier())
+ if (IdentifierInfo *II = FD->getIdentifier()) {
+ // Detect duplicate member names.
+ if (!FieldIDs.insert(II).second) {
+ Diag(FD->getLocation(), diag::err_duplicate_member, II->getName());
+ // Find the previous decl.
+ SourceLocation PrevLoc;
+ for (unsigned i = 0, e = RecFields.size(); ; ++i) {
+ assert(i != e && "Didn't find previous def!");
+ if (RecFields[i]->getIdentifier() == II) {
+ PrevLoc = RecFields[i]->getLocation();
+ break;
+ }
+ }
+ Diag(PrevLoc, diag::err_previous_definition);
+ delete FD;
+ continue;
+ }
++NumNamedMembers;
+ }
// Remember good fields.
RecFields.push_back(FD);
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=39303&r1=39302&r2=39303&view=diff
==============================================================================
--- cfe/cfe/trunk/include/clang/Basic/DiagnosticKinds.def (original)
+++ cfe/cfe/trunk/include/clang/Basic/DiagnosticKinds.def Wed Jul 11 11:42:45 2007
@@ -435,6 +435,8 @@
"ISO C forbids forward references to 'enum' types")
DIAG(err_redefinition_of_enumerator, ERROR,
"redefinition of enumerator '%s'")
+DIAG(err_duplicate_member, ERROR,
+ "duplicate member '%s'")
DIAG(warn_implicit_function_decl, WARNING,
"implicit declaration of function '%s'")
More information about the cfe-commits
mailing list