// Chain & install the interface decl into the identifier.
IDecl->setNext(ClassName->getFETokenInfo<ScopedDecl>());
ClassName->setFETokenInfo(IDecl);
+
+ // Remember that this needs to be removed when the scope is popped.
+ TUScope->AddDecl(IDecl);
}
if (SuperName) {
IDecl->setNext(ClassName->getFETokenInfo<ScopedDecl>());
ClassName->setFETokenInfo(IDecl);
+ // Remember that this needs to be removed when the scope is popped.
+ TUScope->AddDecl(IDecl);
}
// Check that there is no duplicate implementation of this class.
llvm::SmallVector<ObjcInterfaceDecl*, 32> Interfaces;
for (unsigned i = 0; i != NumElts; ++i) {
- ObjcInterfaceDecl *IDecl = getObjCInterfaceDecl(IdentList[i]);
+ // Check for another declaration kind with the same name.
+ ScopedDecl *PrevDecl = LookupInterfaceDecl(IdentList[i]);
+ if (PrevDecl && !isa<ObjcInterfaceDecl>(PrevDecl)) {
+ Diag(AtClassLoc, diag::err_redefinition_different_kind,
+ IdentList[i]->getName());
+ Diag(PrevDecl->getLocation(), diag::err_previous_definition);
+ }
+ ObjcInterfaceDecl *IDecl = dyn_cast_or_null<ObjcInterfaceDecl>(PrevDecl);
if (!IDecl) { // Not already seen? Make a forward decl.
- IDecl = new ObjcInterfaceDecl(SourceLocation(), 0, IdentList[i], true);
+ IDecl = new ObjcInterfaceDecl(AtClassLoc, 0, IdentList[i], true);
// Chain & install the interface decl into the identifier.
IDecl->setNext(IdentList[i]->getFETokenInfo<ScopedDecl>());
IdentList[i]->setFETokenInfo(IDecl);
--- /dev/null
+// RUN: clang -fsyntax-only -verify %s
+
+@interface Foo // expected-error {{previous definition is here}}
+@end
+
+float Foo; // expected-error {{redefinition of 'Foo' as different kind of symbol}}
+
+@class Bar; // expected-error {{previous definition is here}}
+
+typedef int Bar; // expected-error {{redefinition of 'Bar' as different kind of symbol}}
+
+@implementation FooBar // expected-warning {{cannot find interface declaration for 'FooBar'}}
+@end
+
+
+typedef int OBJECT; // expected-error {{previous definition is here}}
+
+@class OBJECT ; // expected-error {{redefinition of 'OBJECT' as different kind of symbol}}
+
+
+typedef int Gorf; // expected-error {{previous definition is here}}
+
+@interface Gorf @end // expected-error {{redefinition of 'Gorf' as different kind of symbol}} \
+ // expected-error {{previous definition is here}}
+
+void Gorf() // expected-error {{redefinition of 'Gorf' as different kind of symbol}}
+{
+ int Bar, Foo, FooBar;
+}
@interface INTF @end // expected-error {{redefinition of 'INTF' as different kind of symbol}}
-@interface OBJECT @end
+@interface OBJECT @end // expected-error {{previous definition is here}}
@interface INTF1 : OBJECT @end
@interface INTF1 : OBJECT @end // expected-error {{duplicate interface declaration for class 'INTF1'}
-typedef int OBJECT; // expected-error {{previous definition is here}}
+typedef int OBJECT; // expected-error {{previous definition is here}} \
+ expected-error {{redefinition of 'OBJECT' as different kind of symbol}}
@interface INTF2 : OBJECT @end // expected-error {{redefinition of 'OBJECT' as different kind of symbol}}