forked from OSchip/llvm-project
Implement enough of the 'auto' keyword so we can claim to support N2546.
llvm-svn: 74307
This commit is contained in:
parent
a720af1370
commit
082acded44
|
@ -192,6 +192,7 @@ public:
|
||||||
QualType VoidPtrTy, NullPtrTy;
|
QualType VoidPtrTy, NullPtrTy;
|
||||||
QualType OverloadTy;
|
QualType OverloadTy;
|
||||||
QualType DependentTy;
|
QualType DependentTy;
|
||||||
|
QualType UndeducedAutoTy;
|
||||||
|
|
||||||
ASTContext(const LangOptions& LOpts, SourceManager &SM, TargetInfo &t,
|
ASTContext(const LangOptions& LOpts, SourceManager &SM, TargetInfo &t,
|
||||||
IdentifierTable &idents, SelectorTable &sels,
|
IdentifierTable &idents, SelectorTable &sels,
|
||||||
|
|
|
@ -572,7 +572,10 @@ public:
|
||||||
NullPtr, // This is the type of C++0x 'nullptr'.
|
NullPtr, // This is the type of C++0x 'nullptr'.
|
||||||
|
|
||||||
Overload, // This represents the type of an overloaded function declaration.
|
Overload, // This represents the type of an overloaded function declaration.
|
||||||
Dependent // This represents the type of a type-dependent expression.
|
Dependent, // This represents the type of a type-dependent expression.
|
||||||
|
|
||||||
|
UndeducedAuto // In C++0x, this represents the type of an auto variable
|
||||||
|
// that has not been deduced yet.
|
||||||
};
|
};
|
||||||
private:
|
private:
|
||||||
Kind TypeKind;
|
Kind TypeKind;
|
||||||
|
|
|
@ -83,6 +83,7 @@ public:
|
||||||
TST_typeofType,
|
TST_typeofType,
|
||||||
TST_typeofExpr,
|
TST_typeofExpr,
|
||||||
TST_decltype, // C++0x decltype
|
TST_decltype, // C++0x decltype
|
||||||
|
TST_auto, // C++0x auto
|
||||||
TST_error // erroneous type
|
TST_error // erroneous type
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -179,6 +179,10 @@ void ASTContext::InitBuiltinTypes() {
|
||||||
// expressions.
|
// expressions.
|
||||||
InitBuiltinType(DependentTy, BuiltinType::Dependent);
|
InitBuiltinType(DependentTy, BuiltinType::Dependent);
|
||||||
|
|
||||||
|
// Placeholder type for C++0x auto declarations whose real type has
|
||||||
|
// not yet been deduced.
|
||||||
|
InitBuiltinType(UndeducedAutoTy, BuiltinType::UndeducedAuto);
|
||||||
|
|
||||||
// C99 6.2.5p11.
|
// C99 6.2.5p11.
|
||||||
FloatComplexTy = getComplexType(FloatTy);
|
FloatComplexTy = getComplexType(FloatTy);
|
||||||
DoubleComplexTy = getComplexType(DoubleTy);
|
DoubleComplexTy = getComplexType(DoubleTy);
|
||||||
|
|
|
@ -539,6 +539,9 @@ void CXXNameMangler::mangleType(const BuiltinType *T) {
|
||||||
assert(false &&
|
assert(false &&
|
||||||
"Overloaded and dependent types shouldn't get to name mangling");
|
"Overloaded and dependent types shouldn't get to name mangling");
|
||||||
break;
|
break;
|
||||||
|
case BuiltinType::UndeducedAuto:
|
||||||
|
assert(0 && "Should not see undeduced auto here");
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1909,6 +1909,9 @@ void PCHWriter::AddTypeRef(QualType T, RecordData &Record) {
|
||||||
case BuiltinType::NullPtr: ID = pch::PREDEF_TYPE_NULLPTR_ID; break;
|
case BuiltinType::NullPtr: ID = pch::PREDEF_TYPE_NULLPTR_ID; break;
|
||||||
case BuiltinType::Overload: ID = pch::PREDEF_TYPE_OVERLOAD_ID; break;
|
case BuiltinType::Overload: ID = pch::PREDEF_TYPE_OVERLOAD_ID; break;
|
||||||
case BuiltinType::Dependent: ID = pch::PREDEF_TYPE_DEPENDENT_ID; break;
|
case BuiltinType::Dependent: ID = pch::PREDEF_TYPE_DEPENDENT_ID; break;
|
||||||
|
case BuiltinType::UndeducedAuto:
|
||||||
|
assert(0 && "Should not see undeduced auto here");
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
Record.push_back((ID << 3) | T.getCVRQualifiers());
|
Record.push_back((ID << 3) | T.getCVRQualifiers());
|
||||||
|
|
|
@ -173,6 +173,7 @@ const char *DeclSpec::getSpecifierName(DeclSpec::TST T) {
|
||||||
case DeclSpec::TST_typename: return "type-name";
|
case DeclSpec::TST_typename: return "type-name";
|
||||||
case DeclSpec::TST_typeofType:
|
case DeclSpec::TST_typeofType:
|
||||||
case DeclSpec::TST_typeofExpr: return "typeof";
|
case DeclSpec::TST_typeofExpr: return "typeof";
|
||||||
|
case DeclSpec::TST_auto: return "auto";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -926,7 +926,10 @@ void Parser::ParseDeclarationSpecifiers(DeclSpec &DS,
|
||||||
isInvalid = DS.SetStorageClassSpec(DeclSpec::SCS_static, Loc, PrevSpec);
|
isInvalid = DS.SetStorageClassSpec(DeclSpec::SCS_static, Loc, PrevSpec);
|
||||||
break;
|
break;
|
||||||
case tok::kw_auto:
|
case tok::kw_auto:
|
||||||
isInvalid = DS.SetStorageClassSpec(DeclSpec::SCS_auto, Loc, PrevSpec);
|
if (getLang().CPlusPlus0x)
|
||||||
|
isInvalid = DS.SetTypeSpecType(DeclSpec::TST_auto, Loc, PrevSpec);
|
||||||
|
else
|
||||||
|
isInvalid = DS.SetStorageClassSpec(DeclSpec::SCS_auto, Loc, PrevSpec);
|
||||||
break;
|
break;
|
||||||
case tok::kw_register:
|
case tok::kw_register:
|
||||||
isInvalid = DS.SetStorageClassSpec(DeclSpec::SCS_register, Loc, PrevSpec);
|
isInvalid = DS.SetStorageClassSpec(DeclSpec::SCS_register, Loc, PrevSpec);
|
||||||
|
|
|
@ -245,6 +245,11 @@ QualType Sema::ConvertDeclSpecToType(const DeclSpec &DS,
|
||||||
Result = Context.getDecltypeType(E);
|
Result = Context.getDecltypeType(E);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
case DeclSpec::TST_auto: {
|
||||||
|
// TypeQuals handled by caller.
|
||||||
|
Result = Context.UndeducedAutoTy;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
case DeclSpec::TST_error:
|
case DeclSpec::TST_error:
|
||||||
Result = Context.IntTy;
|
Result = Context.IntTy;
|
||||||
|
|
|
@ -0,0 +1,5 @@
|
||||||
|
// RUN: clang-cc -fsyntax-only -verify %s -std=c++0x
|
||||||
|
void f() {
|
||||||
|
auto int a; // expected-error{{cannot combine with previous 'auto' declaration specifier}}
|
||||||
|
int auto b; // expected-error{{cannot combine with previous 'int' declaration specifier}}
|
||||||
|
}
|
|
@ -0,0 +1,5 @@
|
||||||
|
// RUN: clang-cc -fsyntax-only -verify %s -std=c++98
|
||||||
|
void f() {
|
||||||
|
auto int a;
|
||||||
|
int auto b;
|
||||||
|
}
|
Loading…
Reference in New Issue