TUScope = S;
}
-QualType Sema::GetObjcIdType() {
+/// GetObjcIdType - The following method assumes that "id" is imported
+/// via <objc/objc.h>. This is the way GCC worked for almost 20 years.
+/// In GCC 4.0, "id" is now a built-in type. Unfortunately, typedefs *cannot* be
+/// redefined (even if they are identical). To allow a built-in types to coexist
+/// with <objc/objc.h>, GCC has a special hack on decls (DECL_IN_SYSTEM_HEADER).
+/// For now, we will *not* install id as a built-in. FIXME: reconsider this.
+QualType Sema::GetObjcIdType(SourceLocation Loc) {
assert(TUScope && "GetObjcIdType(): Top-level scope is null");
- if (ObjcIdType.isNull()) {
+ if (!ObjcIdTypedef) {
IdentifierInfo *IdIdent = &Context.Idents.get("id");
ScopedDecl *IdDecl = LookupScopedDecl(IdIdent, Decl::IDNS_Ordinary,
SourceLocation(), TUScope);
- TypedefDecl *IdTypedef = dyn_cast_or_null<TypedefDecl>(IdDecl);
- assert(IdTypedef && "GetObjcIdType(): Couldn't find 'id' type");
- ObjcIdType = Context.getTypedefType(IdTypedef);
+ ObjcIdTypedef = dyn_cast_or_null<TypedefDecl>(IdDecl);
+ if (!ObjcIdTypedef) {
+ Diag(Loc, diag::err_missing_id_definition);
+ return QualType();
+ }
}
- return ObjcIdType;
+ return Context.getTypedefType(ObjcIdTypedef);
}
KnownFunctionIDs[ id_vprintf ] = &IT.get("vprintf");
TUScope = 0;
- ObjcIdType = QualType();
+ ObjcIdTypedef = 0;
}
void Sema::DeleteExpr(ExprTy *E) {
#include "llvm/ADT/SmallVector.h"
#include "llvm/ADT/DenseSet.h"
#include "llvm/ADT/SmallPtrSet.h"
-#include "clang/AST/Type.h"
#include <vector>
#include <string>
/// For example, user-defined classes, built-in "id" type, etc.
Scope *TUScope;
- /// ObjcIdType - built-in type for "id".
- QualType ObjcIdType;
+ /// ObjcIdTypedef - built-in typedef for "id".
+ TypedefDecl *ObjcIdTypedef;
public:
Sema(Preprocessor &pp, ASTContext &ctxt, std::vector<Decl*> &prevInGroup);
const ObjcMethodDecl *PrevMethod);
/// GetObjcIdType - Getter for the build-in "id" type.
- QualType GetObjcIdType();
+ QualType GetObjcIdType(SourceLocation Loc = SourceLocation());
//===--------------------------------------------------------------------===//
// Statement Parsing Callbacks: SemaStmt.cpp.
if (ArgTypes[i])
argType = QualType::getFromOpaquePtr(ArgTypes[i]);
else
- argType = GetObjcIdType();
+ argType = GetObjcIdType(MethodLoc);
ParmVarDecl* Param = new ParmVarDecl(SourceLocation(/*FIXME*/), ArgNames[i],
argType, VarDecl::None, 0);
Params.push_back(Param);
if (ReturnType)
resultDeclType = QualType::getFromOpaquePtr(ReturnType);
else // get the type for "id".
- resultDeclType = GetObjcIdType();
+ resultDeclType = GetObjcIdType(MethodLoc);
ObjcMethodDecl* ObjcMethod = new ObjcMethodDecl(MethodLoc, Sel,
resultDeclType, 0, -1, AttrList,
08FB7793FE84155DC02AAC07 /* Project object */ = {
isa = PBXProject;
buildConfigurationList = 1DEB923508733DC60010E9CD /* Build configuration list for PBXProject "clang" */;
- compatibilityVersion = "Xcode 2.4";
hasScannedForEncodings = 1;
mainGroup = 08FB7794FE84155DC02AAC07 /* clang */;
projectDirPath = "";
"previous declaration is here")
DIAG(err_undeclared_protocol, ERROR,
"cannot find protocol declaration for '%0'")
+DIAG(err_missing_id_definition, ERROR,
+ "cannot find definition of 'id'")
//===----------------------------------------------------------------------===//
--- /dev/null
+// RUN: clang %s -parse-ast -verify
+
+id obj; // expected-error{{expected '=', ',', ';', 'asm', or '__attribute__' after declarator}}
+
+@interface Foo
+
+- defaultToId; // expected-error{{cannot find definition of 'id'}}
+
+@end