PrevDecl = 0; // If in outer scope, it isn't the same thing.
Decl *New;
+ bool InvalidDecl = false;
+
if (D.getDeclSpec().getStorageClassSpec() == DeclSpec::SCS_typedef) {
assert(Init == 0 && "Can't have initializer for a typedef!");
TypedefDecl *NewTD = ParseTypedefDecl(S, D, LastDeclarator);
// then it shall have block scope.
if (ArrayType *ary = dyn_cast<ArrayType>(NewTD->getUnderlyingType())) {
if (VerifyConstantArrayType(ary, D.getIdentifierLoc()))
- return 0;
+ InvalidDecl = true;
}
}
} else if (D.isFunctionDeclarator()) {
assert(Init == 0 && "Can't have an initializer for a functiondecl!");
+
QualType R = GetTypeForDeclarator(D, S);
- if (R.isNull()) return 0; // FIXME: "auto func();" passes through...
+ assert(!R.isNull() && "GetTypeForDeclarator() returned null type");
FunctionDecl::StorageClass SC;
switch (D.getDeclSpec().getStorageClassSpec()) {
case DeclSpec::SCS_register:
Diag(D.getIdentifierLoc(), diag::err_typecheck_sclass_func,
R.getAsString());
- return 0;
+ InvalidDecl = true;
+ break;
case DeclSpec::SCS_unspecified: SC = FunctionDecl::None; break;
case DeclSpec::SCS_extern: SC = FunctionDecl::Extern; break;
case DeclSpec::SCS_static: SC = FunctionDecl::Static; break;
New = NewFD;
} else {
QualType R = GetTypeForDeclarator(D, S);
-
assert(!R.isNull() && "GetTypeForDeclarator() returned null type");
- bool InvalidDecl = false;
VarDecl *NewVD;
VarDecl::StorageClass SC;
}
NewVD = new BlockVarDecl(D.getIdentifierLoc(), II, R, SC, LastDeclarator);
}
- if (InvalidDecl)
- NewVD->setInvalidDecl();
-
// Handle attributes prior to checking for duplicates in MergeVarDecl
HandleDeclAttributes(NewVD, D.getDeclSpec().getAttributes(),
D.getAttributes());
if (S->getParent() == 0)
AddTopLevelDecl(New, LastDeclarator);
+
+ // If any semantic error occurred, mark the decl as invalid.
+ if (D.getInvalidType() || InvalidDecl)
+ New->setInvalidDecl();
return New;
}
assert(D.getIdentifier() && "Wrong callback for declspec without declarator");
QualType T = GetTypeForDeclarator(D, S);
- if (T.isNull()) return 0;
+ assert(!T.isNull() && "GetTypeForDeclarator() returned null type");
// Scope manipulation handled by caller.
- return new TypedefDecl(D.getIdentifierLoc(), D.getIdentifier(), T,
- LastDeclarator);
+ TypedefDecl *NewTD = new TypedefDecl(D.getIdentifierLoc(), D.getIdentifier(),
+ T, LastDeclarator);
+ if (D.getInvalidType())
+ NewTD->setInvalidDecl();
+ return NewTD;
}
}
QualType T = GetTypeForDeclarator(D, S);
- if (T.isNull()) return 0;
+ assert(!T.isNull() && "GetTypeForDeclarator() returned null type");
+ bool InvalidDecl = false;
// C99 6.7.2.1p8: A member of a structure or union may have any type other
// than a variably modified type.
if (const ArrayType *ary = T->getAsArrayType()) {
if (VerifyConstantArrayType(ary, Loc))
- return 0;
+ InvalidDecl = true;
}
// FIXME: Chain fielddecls together.
- return new FieldDecl(Loc, II, T, 0);
+ FieldDecl *NewFD = new FieldDecl(Loc, II, T, 0);
+ if (D.getInvalidType() || InvalidDecl)
+ NewFD->setInvalidDecl();
+ return NewFD;
}
void Sema::ParseRecordBody(SourceLocation RecLoc, DeclTy *RecDecl,
assert(D.getIdentifier() == 0 && "Type name should have no identifier!");
QualType T = GetTypeForDeclarator(D, S);
+
+ assert(!T.isNull() && "GetTypeForDeclarator() returned null type");
- // If the type of the declarator was invalid, this is an invalid typename.
- if (T.isNull())
- return true;
-
+ // In this context, we *do not* check D.getInvalidType(). If the declarator
+ // type was invalid, GetTypeForDeclarator() still returns a "valid" type,
+ // though it will not reflect the user specified type.
return T.getAsOpaquePtr();
}
// just want the type converted.
QualType T = GetTypeForDeclarator(D, S);
- // If the type of the declarator was invalid, this is an invalid typename.
- if (T.isNull())
- return true;
-
+ assert(!T.isNull() && "GetTypeForDeclarator() returned null type");
+
+ // In this context, we *do not* check D.getInvalidType(). If the declarator
+ // type was invalid, GetTypeForDeclarator() still returns a "valid" type,
+ // though it will not reflect the user specified type.
return T.getAsOpaquePtr();
}