]> granicus.if.org Git - clang/commitdiff
PR16529: Don't forget to add the CXXFunctionalCastExpr type sugar to an
authorRichard Smith <richard-llvm@metafoo.co.uk>
Mon, 23 Sep 2013 02:20:00 +0000 (02:20 +0000)
committerRichard Smith <richard-llvm@metafoo.co.uk>
Mon, 23 Sep 2013 02:20:00 +0000 (02:20 +0000)
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
test/SemaCXX/decltype.cpp

index f0417f724950adb44fa8126b536edc3e880786ca..e6dd5fb1af4106aa68834a2bc40595384c0450d5 100644 (file)
@@ -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<InitListExpr>(Result.get())) {
+  if (Result.isInvalid() || !ListInitialization)
+    return Result;
+
+  Expr *Inner = Result.get();
+  if (CXXBindTemporaryExpr *BTE = dyn_cast_or_null<CXXBindTemporaryExpr>(Inner))
+    Inner = BTE->getSubExpr();
+  if (isa<InitListExpr>(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<InitListExpr>(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?
index ccde3dcfb3123f81822b3c21c79e2450d8224da3..d6e85d285dd143b50357e23f897c3bbc0e8dea31 100644 (file)
@@ -37,6 +37,14 @@ struct C {
                          // expected-error {{expected ')'}} expected-note {{to match this '('}}
 };
 
+namespace PR16529 {
+  struct U {};
+  template <typename T> struct S {
+    static decltype(T{}, U{}) &f();
+  };
+  U &r = S<int>::f();
+}
+
 template<typename>
 class conditional {
 };