[PATCH] D147591: [clang][Interp] Handle CXXTemporaryObjectExprs

Timm Bäder via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Sat May 6 06:19:59 PDT 2023


tbaeder added inline comments.


================
Comment at: clang/test/AST/Interp/records.cpp:317-318
     {
-      auto T = Test(Arr, Pos);
+      Test(Arr, Pos);
       // End of scope, should destroy Test.
     }
----------------
aaron.ballman wrote:
> Nit: nothing actually tests that this object is destroyed correctly. Here's an interesting test to consider:
> ```
> struct S {
>   constexpr S() {}
>   constexpr ~S() noexcept(false) { throw 12; }
> };
> 
> constexpr int f() {
>   S{};
>   return 12;
> }
> 
> static_assert(f() == 12);
> ```
> That should fail because `~S()` would hit the `throw` expression and thus is not valid. Note, you'll need to add `-Wno-invalid-constexpr` to your test to avoid the warning-defaults-to-error about the destructor never producing a constant expression.
There are multiple reasons why that sample is not rejected right now, one I can easily fix in a follow-up patch, the other one would actually require us to recognize the `throw` and reject it with a proper diagnostic.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D147591



More information about the cfe-commits mailing list