diff options
author | Zhihao Yuan <zy@miator.net> | 2017-12-11 18:29:54 +0000 |
---|---|---|
committer | Zhihao Yuan <zy@miator.net> | 2017-12-11 18:29:54 +0000 |
commit | 00c9dfdfd0941a52902d81a8e377b28037ee494d (patch) | |
tree | 1662153a646961bd8a07f06b45a953f3f5a9f95a /clang/lib/Sema | |
parent | 5512525c5d87b241adcca122fd315c073066eadb (diff) | |
download | bcm5719-llvm-00c9dfdfd0941a52902d81a8e377b28037ee494d.tar.gz bcm5719-llvm-00c9dfdfd0941a52902d81a8e377b28037ee494d.zip |
P0620 follow-up: deducing `auto` from braced-init-list in new expr
Summary:
This is a side-effect brought in by p0620r0, which allows other placeholder types (derived from `auto` and `decltype(auto)`) to be usable in a `new` expression with a single-clause //braced-init-list// as its initializer (8.3.4 [expr.new]/2). N3922 defined its semantics.
References:
http://wg21.link/p0620r0
http://wg21.link/n3922
Reviewers: rsmith, aaron.ballman
Reviewed By: rsmith
Subscribers: cfe-commits
Differential Revision: https://reviews.llvm.org/D39451
llvm-svn: 320401
Diffstat (limited to 'clang/lib/Sema')
-rw-r--r-- | clang/lib/Sema/SemaExprCXX.cpp | 17 |
1 files changed, 12 insertions, 5 deletions
diff --git a/clang/lib/Sema/SemaExprCXX.cpp b/clang/lib/Sema/SemaExprCXX.cpp index cd0d7157415..9c842ded1e1 100644 --- a/clang/lib/Sema/SemaExprCXX.cpp +++ b/clang/lib/Sema/SemaExprCXX.cpp @@ -1748,20 +1748,27 @@ Sema::BuildCXXNew(SourceRange Range, bool UseGlobal, if (AllocType.isNull()) return ExprError(); } else if (Deduced) { + bool Braced = (initStyle == CXXNewExpr::ListInit); + if (NumInits == 1) { + if (auto p = dyn_cast_or_null<InitListExpr>(Inits[0])) { + Inits = p->getInits(); + NumInits = p->getNumInits(); + Braced = true; + } + } + if (initStyle == CXXNewExpr::NoInit || NumInits == 0) return ExprError(Diag(StartLoc, diag::err_auto_new_requires_ctor_arg) << AllocType << TypeRange); - if (initStyle == CXXNewExpr::ListInit || - (NumInits == 1 && isa<InitListExpr>(Inits[0]))) - return ExprError(Diag(Inits[0]->getLocStart(), - diag::err_auto_new_list_init) - << AllocType << TypeRange); if (NumInits > 1) { Expr *FirstBad = Inits[1]; return ExprError(Diag(FirstBad->getLocStart(), diag::err_auto_new_ctor_multiple_expressions) << AllocType << TypeRange); } + if (Braced && !getLangOpts().CPlusPlus17) + Diag(Initializer->getLocStart(), diag::ext_auto_new_list_init) + << AllocType << TypeRange; Expr *Deduce = Inits[0]; QualType DeducedType; if (DeduceAutoType(AllocTypeInfo, Deduce, DeducedType) == DAR_Failed) |