From 25b24eb889d633c4666001af107d8eb5c45dd065 Mon Sep 17 00:00:00 2001 From: Richard Smith Date: Mon, 23 Sep 2013 02:20:00 +0000 Subject: [PATCH] PR16529: Don't forget to add the CXXFunctionalCastExpr type sugar to an InitListExpr for a C++11-style T{...} construction, if initialization registered a destructor for it. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@191182 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Sema/SemaExprCXX.cpp | 19 +++++++++++-------- test/SemaCXX/decltype.cpp | 8 ++++++++ 2 files changed, 19 insertions(+), 8 deletions(-) diff --git a/lib/Sema/SemaExprCXX.cpp b/lib/Sema/SemaExprCXX.cpp index f0417f7249..e6dd5fb1af 100644 --- a/lib/Sema/SemaExprCXX.cpp +++ b/lib/Sema/SemaExprCXX.cpp @@ -903,18 +903,21 @@ Sema::BuildCXXTypeConstructExpr(TypeSourceInfo *TInfo, InitializationSequence InitSeq(*this, Entity, Kind, Exprs); ExprResult Result = InitSeq.Perform(*this, Entity, Kind, Exprs); - if (!Result.isInvalid() && ListInitialization && - isa(Result.get())) { + if (Result.isInvalid() || !ListInitialization) + return Result; + + Expr *Inner = Result.get(); + if (CXXBindTemporaryExpr *BTE = dyn_cast_or_null(Inner)) + Inner = BTE->getSubExpr(); + if (isa(Inner)) { // If the list-initialization doesn't involve a constructor call, we'll get // the initializer-list (with corrected type) back, but that's not what we // want, since it will be treated as an initializer list in further // processing. Explicitly insert a cast here. - InitListExpr *List = cast(Result.take()); - Result = Owned(CXXFunctionalCastExpr::Create(Context, List->getType(), - Expr::getValueKindForType(TInfo->getType()), - TInfo, CK_NoOp, List, - /*Path=*/0, - LParenLoc, RParenLoc)); + QualType ResultType = Result.get()->getType(); + Result = Owned(CXXFunctionalCastExpr::Create( + Context, ResultType, Expr::getValueKindForType(TInfo->getType()), TInfo, + CK_NoOp, Result.take(), /*Path=*/ 0, LParenLoc, RParenLoc)); } // FIXME: Improve AST representation? diff --git a/test/SemaCXX/decltype.cpp b/test/SemaCXX/decltype.cpp index ccde3dcfb3..d6e85d285d 100644 --- a/test/SemaCXX/decltype.cpp +++ b/test/SemaCXX/decltype.cpp @@ -37,6 +37,14 @@ struct C { // expected-error {{expected ')'}} expected-note {{to match this '('}} }; +namespace PR16529 { + struct U {}; + template struct S { + static decltype(T{}, U{}) &f(); + }; + U &r = S::f(); +} + template class conditional { }; -- 2.40.0