[clang] [Clang][CWG1815] Support lifetime extension of temporary created by aggregate initialization using a default member initializer (PR #87933)

Richard Smith via cfe-commits cfe-commits at lists.llvm.org
Fri May 3 16:17:30 PDT 2024


================
@@ -269,6 +269,26 @@ void init_capture_init_list() {
   // CHECK: }
 }
 
+void check_dr1815() { // dr1815: yes
+#if __cplusplus >= 201402L
+
+  struct A {
+    int &&r = 0;
+    ~A() {}
+  };
+
+  struct B {
+    A &&a = A{};
+    ~B() {}
+  };
+
+  // CHECK: void @_Z12check_dr1815v()
+  // CHECK: call void @_ZZ12check_dr1815vEN1BD1Ev(
+  // CHECK: call void @_ZZ12check_dr1815vEN1AD1Ev(
+  B a = {};
----------------
zygoloid wrote:

This check of destructor ordering is a bit too subtle for my tastes. How about:
```suggestion
  // CHECK: void @_Z12check_dr1815v()
  B a = {};
  // CHECK: call {{.*}}some_other_function
  extern void some_other_function();
  some_other_function();
  // CHECK: call void @_ZZ12check_dr1815vEN1BD1Ev(
  // CHECK: call void @_ZZ12check_dr1815vEN1AD1Ev(
```
... to really drive home that the `A` temporary isn't destroyed until the end of the function?

https://github.com/llvm/llvm-project/pull/87933


More information about the cfe-commits mailing list