diff options
author | Anders Carlsson <andersca@mac.com> | 2009-06-26 18:41:36 +0000 |
---|---|---|
committer | Anders Carlsson <andersca@mac.com> | 2009-06-26 18:41:36 +0000 |
commit | e89d15944dd3be750a09805ad21222d2fa9321fa (patch) | |
tree | c366f378cf61312ef9fe1ba0dab8279ba15c210d | |
parent | bd0fec9250a783ad67d023e53ab0877a74f0be11 (diff) |
Implement enough of the 'auto' keyword so we can claim to support N2546.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@74307 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r-- | include/clang/AST/ASTContext.h | 1 | ||||
-rw-r--r-- | include/clang/AST/Type.h | 5 | ||||
-rw-r--r-- | include/clang/Parse/DeclSpec.h | 1 | ||||
-rw-r--r-- | lib/AST/ASTContext.cpp | 4 | ||||
-rw-r--r-- | lib/CodeGen/Mangle.cpp | 3 | ||||
-rw-r--r-- | lib/Frontend/PCHWriter.cpp | 3 | ||||
-rw-r--r-- | lib/Parse/DeclSpec.cpp | 1 | ||||
-rw-r--r-- | lib/Parse/ParseDecl.cpp | 5 | ||||
-rw-r--r-- | lib/Sema/SemaType.cpp | 5 | ||||
-rw-r--r-- | test/SemaCXX/auto-cxx0x.cpp | 5 | ||||
-rw-r--r-- | test/SemaCXX/auto-cxx98.cpp | 5 |
11 files changed, 36 insertions, 2 deletions
diff --git a/include/clang/AST/ASTContext.h b/include/clang/AST/ASTContext.h index 2d35b4d990..aa01b7fdf0 100644 --- a/include/clang/AST/ASTContext.h +++ b/include/clang/AST/ASTContext.h @@ -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, diff --git a/include/clang/AST/Type.h b/include/clang/AST/Type.h index 225a423821..321b1f204f 100644 --- a/include/clang/AST/Type.h +++ b/include/clang/AST/Type.h @@ -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; diff --git a/include/clang/Parse/DeclSpec.h b/include/clang/Parse/DeclSpec.h index 10c5ee39ec..300602e514 100644 --- a/include/clang/Parse/DeclSpec.h +++ b/include/clang/Parse/DeclSpec.h @@ -83,6 +83,7 @@ public: TST_typeofType, TST_typeofExpr, TST_decltype, // C++0x decltype + TST_auto, // C++0x auto TST_error // erroneous type }; diff --git a/lib/AST/ASTContext.cpp b/lib/AST/ASTContext.cpp index 16a62fdd8c..12f75ae863 100644 --- a/lib/AST/ASTContext.cpp +++ b/lib/AST/ASTContext.cpp @@ -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); diff --git a/lib/CodeGen/Mangle.cpp b/lib/CodeGen/Mangle.cpp index 24e441a296..b5ad5acc01 100644 --- a/lib/CodeGen/Mangle.cpp +++ b/lib/CodeGen/Mangle.cpp @@ -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; } } diff --git a/lib/Frontend/PCHWriter.cpp b/lib/Frontend/PCHWriter.cpp index 808df70df3..e93219e01d 100644 --- a/lib/Frontend/PCHWriter.cpp +++ b/lib/Frontend/PCHWriter.cpp @@ -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()); diff --git a/lib/Parse/DeclSpec.cpp b/lib/Parse/DeclSpec.cpp index d8c6986f9e..8b3b2851c1 100644 --- a/lib/Parse/DeclSpec.cpp +++ b/lib/Parse/DeclSpec.cpp @@ -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"; } } diff --git a/lib/Parse/ParseDecl.cpp b/lib/Parse/ParseDecl.cpp index c11383c3ec..b2b2f31dd6 100644 --- a/lib/Parse/ParseDecl.cpp +++ b/lib/Parse/ParseDecl.cpp @@ -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); diff --git a/lib/Sema/SemaType.cpp b/lib/Sema/SemaType.cpp index 8a0ad089b6..b584142344 100644 --- a/lib/Sema/SemaType.cpp +++ b/lib/Sema/SemaType.cpp @@ -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; diff --git a/test/SemaCXX/auto-cxx0x.cpp b/test/SemaCXX/auto-cxx0x.cpp new file mode 100644 index 0000000000..33156ef23d --- /dev/null +++ b/test/SemaCXX/auto-cxx0x.cpp @@ -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}} +} diff --git a/test/SemaCXX/auto-cxx98.cpp b/test/SemaCXX/auto-cxx98.cpp new file mode 100644 index 0000000000..14670cd699 --- /dev/null +++ b/test/SemaCXX/auto-cxx98.cpp @@ -0,0 +1,5 @@ +// RUN: clang-cc -fsyntax-only -verify %s -std=c++98 +void f() { + auto int a; + int auto b; +} |