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 OverloadTy;
|
||||
QualType DependentTy;
|
||||
QualType UndeducedAutoTy;
|
||||
|
||||
ASTContext(const LangOptions& LOpts, SourceManager &SM, TargetInfo &t,
|
||||
IdentifierTable &idents, SelectorTable &sels,
|
||||
|
|
|
@ -572,7 +572,10 @@ public:
|
|||
NullPtr, // This is the type of C++0x 'nullptr'.
|
||||
|
||||
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:
|
||||
Kind TypeKind;
|
||||
|
|
|
@ -83,6 +83,7 @@ public:
|
|||
TST_typeofType,
|
||||
TST_typeofExpr,
|
||||
TST_decltype, // C++0x decltype
|
||||
TST_auto, // C++0x auto
|
||||
TST_error // erroneous type
|
||||
};
|
||||
|
||||
|
|
|
@ -179,6 +179,10 @@ void ASTContext::InitBuiltinTypes() {
|
|||
// expressions.
|
||||
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.
|
||||
FloatComplexTy = getComplexType(FloatTy);
|
||||
DoubleComplexTy = getComplexType(DoubleTy);
|
||||
|
|
|
@ -539,6 +539,9 @@ void CXXNameMangler::mangleType(const BuiltinType *T) {
|
|||
assert(false &&
|
||||
"Overloaded and dependent types shouldn't get to name mangling");
|
||||
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::Overload: ID = pch::PREDEF_TYPE_OVERLOAD_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());
|
||||
|
|
|
@ -173,6 +173,7 @@ const char *DeclSpec::getSpecifierName(DeclSpec::TST T) {
|
|||
case DeclSpec::TST_typename: return "type-name";
|
||||
case DeclSpec::TST_typeofType:
|
||||
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);
|
||||
break;
|
||||
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;
|
||||
case tok::kw_register:
|
||||
isInvalid = DS.SetStorageClassSpec(DeclSpec::SCS_register, Loc, PrevSpec);
|
||||
|
|
|
@ -245,6 +245,11 @@ QualType Sema::ConvertDeclSpecToType(const DeclSpec &DS,
|
|||
Result = Context.getDecltypeType(E);
|
||||
break;
|
||||
}
|
||||
case DeclSpec::TST_auto: {
|
||||
// TypeQuals handled by caller.
|
||||
Result = Context.UndeducedAutoTy;
|
||||
break;
|
||||
}
|
||||
|
||||
case DeclSpec::TST_error:
|
||||
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