diff options
author | Richard Smith <richard-llvm@metafoo.co.uk> | 2011-02-21 20:05:19 +0000 |
---|---|---|
committer | Richard Smith <richard-llvm@metafoo.co.uk> | 2011-02-21 20:05:19 +0000 |
commit | 483b9f3bc05c5409e2c6643f1c9d91e21c8ff9d2 (patch) | |
tree | 98392cc5b1045b5eab9c827e4e1ba7cc48e2cc9a /lib/Sema/SemaDecl.cpp | |
parent | 57cbb0de091a05a6510f0a7278ee8da57a4d27fc (diff) |
Tweaks to C++0x deduced auto type support:
* Flag indicating 'we're parsing this auto typed variable's initializer' moved from VarDecl to Sema
* Temporary template parameter list for auto deduction is now allocated on the stack.
* Deduced 'auto' types are now uniqued.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@126139 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Sema/SemaDecl.cpp')
-rw-r--r-- | lib/Sema/SemaDecl.cpp | 27 |
1 files changed, 15 insertions, 12 deletions
diff --git a/lib/Sema/SemaDecl.cpp b/lib/Sema/SemaDecl.cpp index dd30c1261e..3c62c18558 100644 --- a/lib/Sema/SemaDecl.cpp +++ b/lib/Sema/SemaDecl.cpp @@ -3026,11 +3026,11 @@ Sema::ActOnVariableDeclarator(Scope *S, Declarator &D, DeclContext *DC, NewVD = VarDecl::Create(Context, DC, D.getIdentifierLoc(), II, R, TInfo, SC, SCAsWritten); - // If this decl has an auto type in need of deduction, mark the VarDecl so - // we can diagnose uses of it in its own initializer. - if (D.getDeclSpec().getTypeSpecType() == DeclSpec::TST_auto) { - NewVD->setParsingAutoInit(R->getContainedAutoType()); - } + // If this decl has an auto type in need of deduction, make a note of the + // Decl so we can diagnose uses of it in its own initializer. + if (D.getDeclSpec().getTypeSpecType() == DeclSpec::TST_auto && + R->getContainedAutoType()) + ParsingInitForAutoVars.insert(NewVD); if (D.isInvalidType() || Invalid) NewVD->setInvalidDecl(); @@ -4534,8 +4534,6 @@ void Sema::AddInitializerToDecl(Decl *RealDecl, Expr *Init, // C++0x [decl.spec.auto]p6. Deduce the type which 'auto' stands in for. if (TypeMayContainAuto && VDecl->getType()->getContainedAutoType()) { - VDecl->setParsingAutoInit(false); - QualType DeducedType; if (!DeduceAutoType(VDecl->getType(), Init, DeducedType)) { Diag(VDecl->getLocation(), diag::err_auto_var_deduction_failure) @@ -4800,9 +4798,8 @@ void Sema::ActOnInitializerError(Decl *D) { if (!VD) return; // Auto types are meaningless if we can't make sense of the initializer. - if (VD->isParsingAutoInit()) { - VD->setParsingAutoInit(false); - VD->setInvalidDecl(); + if (ParsingInitForAutoVars.count(D)) { + D->setInvalidDecl(); return; } @@ -4840,8 +4837,6 @@ void Sema::ActOnUninitializedDecl(Decl *RealDecl, // C++0x [dcl.spec.auto]p3 if (TypeMayContainAuto && Type->getContainedAutoType()) { - Var->setParsingAutoInit(false); - Diag(Var->getLocation(), diag::err_auto_var_requires_init) << Var->getDeclName() << Type; Var->setInvalidDecl(); @@ -5044,6 +5039,14 @@ void Sema::CheckCompleteVariableDeclaration(VarDecl *var) { FinalizeVarWithDestructor(var, recordType); } +/// FinalizeDeclaration - called by ParseDeclarationAfterDeclarator to perform +/// any semantic actions necessary after any initializer has been attached. +void +Sema::FinalizeDeclaration(Decl *ThisDecl) { + // Note that we are no longer parsing the initializer for this declaration. + ParsingInitForAutoVars.erase(ThisDecl); +} + Sema::DeclGroupPtrTy Sema::FinalizeDeclaratorGroup(Scope *S, const DeclSpec &DS, Decl **Group, unsigned NumDecls) { |