tbaeder updated this revision to Diff 534174.

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D153653/new/

https://reviews.llvm.org/D153653

Files:
  clang/lib/AST/Interp/ByteCodeExprGen.cpp
  clang/test/AST/Interp/records.cpp


Index: clang/test/AST/Interp/records.cpp
===================================================================
--- clang/test/AST/Interp/records.cpp
+++ clang/test/AST/Interp/records.cpp
@@ -880,3 +880,18 @@
   }
 }
 
+namespace TemporaryObjectExpr {
+  struct F {
+    int a;
+    constexpr F() : a(12) {}
+  };
+  constexpr int foo(F f) {
+    return 0;
+  }
+  /// FIXME: This should also work in C++14, but it needs suport for
+  ///   CXXConstructExpr. I think.
+#if __cplusplus > 201402L
+  static_assert(foo(F()) == 0, "");
+#endif
+
+}
Index: clang/lib/AST/Interp/ByteCodeExprGen.cpp
===================================================================
--- clang/lib/AST/Interp/ByteCodeExprGen.cpp
+++ clang/lib/AST/Interp/ByteCodeExprGen.cpp
@@ -1011,10 +1011,17 @@
 template <class Emitter>
 bool ByteCodeExprGen<Emitter>::VisitCXXTemporaryObjectExpr(
     const CXXTemporaryObjectExpr *E) {
-
   if (std::optional<unsigned> LocalIndex =
           allocateLocal(E, /*IsExtended=*/false)) {
-    return this->visitLocalInitializer(E, *LocalIndex);
+    if (!this->emitGetPtrLocal(*LocalIndex, E))
+      return false;
+
+    if (!this->visitInitializer(E))
+      return false;
+
+    if (DiscardResult)
+      return this->emitPopPtr(E);
+    return true;
   }
   return false;
 }


Index: clang/test/AST/Interp/records.cpp
===================================================================
--- clang/test/AST/Interp/records.cpp
+++ clang/test/AST/Interp/records.cpp
@@ -880,3 +880,18 @@
   }
 }
 
+namespace TemporaryObjectExpr {
+  struct F {
+    int a;
+    constexpr F() : a(12) {}
+  };
+  constexpr int foo(F f) {
+    return 0;
+  }
+  /// FIXME: This should also work in C++14, but it needs suport for
+  ///   CXXConstructExpr. I think.
+#if __cplusplus > 201402L
+  static_assert(foo(F()) == 0, "");
+#endif
+
+}
Index: clang/lib/AST/Interp/ByteCodeExprGen.cpp
===================================================================
--- clang/lib/AST/Interp/ByteCodeExprGen.cpp
+++ clang/lib/AST/Interp/ByteCodeExprGen.cpp
@@ -1011,10 +1011,17 @@
 template <class Emitter>
 bool ByteCodeExprGen<Emitter>::VisitCXXTemporaryObjectExpr(
     const CXXTemporaryObjectExpr *E) {
-
   if (std::optional<unsigned> LocalIndex =
           allocateLocal(E, /*IsExtended=*/false)) {
-    return this->visitLocalInitializer(E, *LocalIndex);
+    if (!this->emitGetPtrLocal(*LocalIndex, E))
+      return false;
+
+    if (!this->visitInitializer(E))
+      return false;
+
+    if (DiscardResult)
+      return this->emitPopPtr(E);
+    return true;
   }
   return false;
 }
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to