diff options
author | Anders Carlsson <andersca@mac.com> | 2009-07-11 00:34:39 +0000 |
---|---|---|
committer | Anders Carlsson <andersca@mac.com> | 2009-07-11 00:34:39 +0000 |
commit | 6a75cd9c1d54625fca7b5477ab9545bcdbd85ea4 (patch) | |
tree | 6dfd55ed4a291d2126b9a954d6f5346b2779b873 | |
parent | 496e89f8d55f7a931c246e820c10f7296a246ac2 (diff) |
Implement more of C++0x 'auto'. A variable with an auto type specifier must have an initializer. Also, move some tests around to match the C++0x draft better.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@75322 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r-- | include/clang/Basic/DiagnosticSemaKinds.td | 2 | ||||
-rw-r--r-- | include/clang/Parse/Action.h | 5 | ||||
-rw-r--r-- | lib/AST/Type.cpp | 2 | ||||
-rw-r--r-- | lib/Parse/ParseDecl.cpp | 4 | ||||
-rw-r--r-- | lib/Sema/Sema.h | 2 | ||||
-rw-r--r-- | lib/Sema/SemaDecl.cpp | 11 | ||||
-rw-r--r-- | test/CXX/dcl.dcl/dcl.spec/dcl.type/dcl.spec.auto/p5.cpp (renamed from test/CXX/dcl.dcl/dcl.spec/dcl.type/dcl.spec.auto/p2.cpp) | 0 |
7 files changed, 21 insertions, 5 deletions
diff --git a/include/clang/Basic/DiagnosticSemaKinds.td b/include/clang/Basic/DiagnosticSemaKinds.td index 2a492fb14d..6926633a40 100644 --- a/include/clang/Basic/DiagnosticSemaKinds.td +++ b/include/clang/Basic/DiagnosticSemaKinds.td @@ -417,6 +417,8 @@ def err_illegal_decl_array_of_auto : Error< def err_auto_not_allowed : Error< "'auto' not allowed in %select{function prototype|struct member|union member" "|class member|exception declaration|template parameter|block literal}0">; +def err_auto_var_requires_init : Error< + "declaration of variable %0 with type %1 requires an initializer">; // Objective-C++ def err_objc_decls_may_only_appear_in_global_scope : Error< diff --git a/include/clang/Parse/Action.h b/include/clang/Parse/Action.h index d969562977..9b8a99c2c1 100644 --- a/include/clang/Parse/Action.h +++ b/include/clang/Parse/Action.h @@ -302,7 +302,10 @@ public: /// ActOnUninitializedDecl - This action is called immediately after /// ActOnDeclarator (when an initializer is *not* present). - virtual void ActOnUninitializedDecl(DeclPtrTy Dcl) { + /// If TypeContainsUndeducedAuto is true, then the type of the declarator + /// has an undeduced 'auto' type somewhere. + virtual void ActOnUninitializedDecl(DeclPtrTy Dcl, + bool TypeContainsUndeducedAuto) { return; } diff --git a/lib/AST/Type.cpp b/lib/AST/Type.cpp index fd368c4815..7a9faac60f 100644 --- a/lib/AST/Type.cpp +++ b/lib/AST/Type.cpp @@ -1006,7 +1006,7 @@ const char *BuiltinType::getName(const LangOptions &LO) const { case NullPtr: return "nullptr_t"; case Overload: return "<overloaded function type>"; case Dependent: return "<dependent type>"; - case UndeducedAuto: return "<undeduced auto type>"; + case UndeducedAuto: return "auto"; } } diff --git a/lib/Parse/ParseDecl.cpp b/lib/Parse/ParseDecl.cpp index 5566751fb9..1ddd20a9ec 100644 --- a/lib/Parse/ParseDecl.cpp +++ b/lib/Parse/ParseDecl.cpp @@ -465,7 +465,9 @@ Parser::DeclPtrTy Parser::ParseDeclarationAfterDeclarator(Declarator &D, CommaLocs.data(), RParenLoc); } } else { - Actions.ActOnUninitializedDecl(ThisDecl); + bool TypeContainsUndeducedAuto = + D.getDeclSpec().getTypeSpecType() == DeclSpec::TST_auto; + Actions.ActOnUninitializedDecl(ThisDecl, TypeContainsUndeducedAuto); } return ThisDecl; diff --git a/lib/Sema/Sema.h b/lib/Sema/Sema.h index 9eb03e36b4..c2a484e75a 100644 --- a/lib/Sema/Sema.h +++ b/lib/Sema/Sema.h @@ -473,7 +473,7 @@ public: virtual void AddInitializerToDecl(DeclPtrTy dcl, FullExprArg init); void AddInitializerToDecl(DeclPtrTy dcl, ExprArg init, bool DirectInit); - void ActOnUninitializedDecl(DeclPtrTy dcl); + void ActOnUninitializedDecl(DeclPtrTy dcl, bool TypeContainsUndeducedAuto); virtual void SetDeclDeleted(DeclPtrTy dcl, SourceLocation DelLoc); virtual DeclGroupPtrTy FinalizeDeclaratorGroup(Scope *S, const DeclSpec &DS, DeclPtrTy *Group, diff --git a/lib/Sema/SemaDecl.cpp b/lib/Sema/SemaDecl.cpp index 2c24dc976e..9c3ef2f6da 100644 --- a/lib/Sema/SemaDecl.cpp +++ b/lib/Sema/SemaDecl.cpp @@ -2756,7 +2756,8 @@ void Sema::AddInitializerToDecl(DeclPtrTy dcl, ExprArg init, bool DirectInit) { return; } -void Sema::ActOnUninitializedDecl(DeclPtrTy dcl) { +void Sema::ActOnUninitializedDecl(DeclPtrTy dcl, + bool TypeContainsUndeducedAuto) { Decl *RealDecl = dcl.getAs<Decl>(); // If there is no declaration, there was an error parsing it. Just ignore it. @@ -2784,6 +2785,14 @@ void Sema::ActOnUninitializedDecl(DeclPtrTy dcl) { return; } + // C++0x [dcl.spec.auto]p3 + if (TypeContainsUndeducedAuto) { + Diag(Var->getLocation(), diag::err_auto_var_requires_init) + << Var->getDeclName() << Type; + Var->setInvalidDecl(); + return; + } + // C++ [dcl.init]p9: // // If no initializer is specified for an object, and the object diff --git a/test/CXX/dcl.dcl/dcl.spec/dcl.type/dcl.spec.auto/p2.cpp b/test/CXX/dcl.dcl/dcl.spec/dcl.type/dcl.spec.auto/p5.cpp index fa3101c673..fa3101c673 100644 --- a/test/CXX/dcl.dcl/dcl.spec/dcl.type/dcl.spec.auto/p2.cpp +++ b/test/CXX/dcl.dcl/dcl.spec/dcl.type/dcl.spec.auto/p5.cpp |