if (Kind != TagDecl::TK_enum)
return ActOnTagStruct(S, Kind, TK, KWLoc, SS, Name, NameLoc, Attr);
- ScopedDecl *PrevDecl;
+ DeclContext *DC = CurContext;
+ ScopedDecl *PrevDecl = 0;
if (Name && SS.isNotEmpty()) {
// We have a nested-name tag ('struct foo::bar').
// Check for invalid 'foo::'.
- DeclContext *DC = static_cast<DeclContext*>(SS.getScopeRep());
- if (DC == 0) {
+ if (SS.isInvalid()) {
Name = 0;
goto CreateNewDecl;
}
+ DC = static_cast<DeclContext*>(SS.getScopeRep());
+ // Look-up name inside 'foo::'.
PrevDecl = dyn_cast_or_null<TagDecl>(LookupDecl(Name, Decl::IDNS_Tag,S,DC));
// A tag 'foo::bar' must already exist.
// If this is a use of a previous tag, or if the tag is already declared
// in the same scope (so that the definition/declaration completes or
// rementions the tag), reuse the decl.
- if (TK == TK_Reference || isDeclInScope(PrevDecl, CurContext, S)) {
+ if (TK == TK_Reference || isDeclInScope(PrevDecl, DC, S)) {
// Make sure that this wasn't declared as an enum and now used as a
// struct or something similar.
if (PrevTagDecl->getTagKind() != Kind) {
// type.
} else {
// PrevDecl is a namespace.
- if (isDeclInScope(PrevDecl, CurContext, S)) {
+ if (isDeclInScope(PrevDecl, DC, S)) {
// The tag name clashes with a namespace name, issue an error and
// recover by making this tag be anonymous.
Diag(NameLoc, diag::err_redefinition_different_kind, Name->getName());
if (Kind == TagDecl::TK_enum) {
// FIXME: Tag decls should be chained to any simultaneous vardecls, e.g.:
// enum X { A, B, C } D; D should chain to X.
- New = EnumDecl::Create(Context, CurContext, Loc, Name, 0);
+ New = EnumDecl::Create(Context, DC, Loc, Name, 0);
// If this is an undefined enum, warn.
if (TK != TK_Definition) Diag(Loc, diag::ext_forward_ref_enum);
} else {
// struct X { int A; } D; D should chain to X.
if (getLangOptions().CPlusPlus)
// FIXME: Look for a way to use RecordDecl for simple structs.
- New = CXXRecordDecl::Create(Context, Kind, CurContext, Loc, Name);
+ New = CXXRecordDecl::Create(Context, Kind, DC, Loc, Name);
else
- New = RecordDecl::Create(Context, Kind, CurContext, Loc, Name);
+ New = RecordDecl::Create(Context, Kind, DC, Loc, Name);
}
// If this has an identifier, add it to the scope stack.
SourceLocation KWLoc, const CXXScopeSpec &SS,
IdentifierInfo *Name, SourceLocation NameLoc,
AttributeList *Attr) {
- ScopedDecl *PrevDecl;
+ DeclContext *DC = CurContext;
+ ScopedDecl *PrevDecl = 0;
if (Name && SS.isNotEmpty()) {
// We have a nested-name tag ('struct foo::bar').
// Check for invalid 'foo::'.
- DeclContext *DC = static_cast<DeclContext*>(SS.getScopeRep());
- if (DC == 0) {
+ if (SS.isInvalid()) {
Name = 0;
goto CreateNewDecl;
}
+ DC = static_cast<DeclContext*>(SS.getScopeRep());
+ // Look-up name inside 'foo::'.
PrevDecl = dyn_cast_or_null<TagDecl>(LookupDecl(Name, Decl::IDNS_Tag,S,DC));
// A tag 'foo::bar' must already exist.
// If this is a use of a previous tag, or if the tag is already declared
// in the same scope (so that the definition/declaration completes or
// rementions the tag), reuse the decl.
- if (TK == TK_Reference || isDeclInScope(PrevDecl, CurContext, S)) {
+ if (TK == TK_Reference || isDeclInScope(PrevDecl, DC, S)) {
// Make sure that this wasn't declared as an enum and now used as a
// struct or something similar.
if (PrevTagDecl->getTagKind() != Kind) {
}
} else {
// PrevDecl is a namespace.
- if (isDeclInScope(PrevDecl, CurContext, S)) {
+ if (isDeclInScope(PrevDecl, DC, S)) {
// The tag name clashes with a namespace name, issue an error and
// recover by making this tag be anonymous.
Diag(NameLoc, diag::err_redefinition_different_kind, Name->getName());
// struct X { int A; } D; D should chain to X.
if (getLangOptions().CPlusPlus)
// FIXME: Look for a way to use RecordDecl for simple structs.
- New = CXXRecordDecl::Create(Context, Kind, CurContext, Loc, Name,
+ New = CXXRecordDecl::Create(Context, Kind, DC, Loc, Name,
dyn_cast_or_null<CXXRecordDecl>(PrevDecl));
else
- New = RecordDecl::Create(Context, Kind, CurContext, Loc, Name,
+ New = RecordDecl::Create(Context, Kind, DC, Loc, Name,
dyn_cast_or_null<RecordDecl>(PrevDecl));
// If this has an identifier, add it to the scope stack.