diff options
Diffstat (limited to 'lib/Sema')
-rw-r--r-- | lib/Sema/SemaDeclCXX.cpp | 15 | ||||
-rw-r--r-- | lib/Sema/SemaTemplateInstantiateDecl.cpp | 7 |
2 files changed, 14 insertions, 8 deletions
diff --git a/lib/Sema/SemaDeclCXX.cpp b/lib/Sema/SemaDeclCXX.cpp index 46a47a2215..56b526b1d7 100644 --- a/lib/Sema/SemaDeclCXX.cpp +++ b/lib/Sema/SemaDeclCXX.cpp @@ -8898,8 +8898,6 @@ void Sema::AddCXXDirectInitializerToDecl(Decl *RealDecl, MultiExprArg Exprs, SourceLocation RParenLoc, bool TypeMayContainAuto) { - assert(Exprs.size() != 0 && Exprs.get() && "missing expressions"); - // If there is no declaration, there was an error parsing it. Just ignore // the initializer. if (RealDecl == 0) @@ -8912,9 +8910,18 @@ void Sema::AddCXXDirectInitializerToDecl(Decl *RealDecl, return; } - // C++0x [decl.spec.auto]p6. Deduce the type which 'auto' stands in for. + // C++0x [dcl.spec.auto]p6. Deduce the type which 'auto' stands in for. if (TypeMayContainAuto && VDecl->getType()->getContainedAutoType()) { - // FIXME: n3225 doesn't actually seem to indicate this is ill-formed + if (Exprs.size() == 0) { + // It isn't possible to write this directly, but it is possible to + // end up in this situation with "auto x(some_pack...);" + Diag(LParenLoc, diag::err_auto_var_init_no_expression) + << VDecl->getDeclName() << VDecl->getType() + << VDecl->getSourceRange(); + RealDecl->setInvalidDecl(); + return; + } + if (Exprs.size() > 1) { Diag(Exprs.get()[1]->getSourceRange().getBegin(), diag::err_auto_var_init_multiple_expressions) diff --git a/lib/Sema/SemaTemplateInstantiateDecl.cpp b/lib/Sema/SemaTemplateInstantiateDecl.cpp index 1f87983805..00addc2d83 100644 --- a/lib/Sema/SemaTemplateInstantiateDecl.cpp +++ b/lib/Sema/SemaTemplateInstantiateDecl.cpp @@ -393,16 +393,15 @@ Decl *TemplateDeclInstantiator::VisitVarDecl(VarDecl *D) { if (!SemaRef.InstantiateInitializer(D->getInit(), TemplateArgs, LParenLoc, InitArgs, RParenLoc)) { bool TypeMayContainAuto = true; - // Attach the initializer to the declaration, if we have one. - if (InitArgs.size() == 0) - SemaRef.ActOnUninitializedDecl(Var, TypeMayContainAuto); - else if (D->hasCXXDirectInitializer()) { + if (D->hasCXXDirectInitializer()) { // Add the direct initializer to the declaration. SemaRef.AddCXXDirectInitializerToDecl(Var, LParenLoc, move_arg(InitArgs), RParenLoc, TypeMayContainAuto); + } else if (InitArgs.size() == 0) { + SemaRef.ActOnUninitializedDecl(Var, TypeMayContainAuto); } else { assert(InitArgs.size() == 1); Expr *Init = InitArgs.take()[0]; |