[PATCH] D139586: [Clang][C++23] Lifetime extension in range-based for loops

Corentin Jabot via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Wed Jan 4 08:28:36 PST 2023


cor3ntin added a comment.

In D139586#4000309 <https://reviews.llvm.org/D139586#4000309>, @hubert.reinterpretcast wrote:

> At least on the surface, it looks like there will be a lot of trouble to deal with default arguments:
>
>   struct A { A(); ~A(); int x[3]; };
>   int (&f(const A & = A()))[3];
>   void bar(int);
>   void foo() {
>     for (auto e : f()) { bar(e); }
>   }
>
> We get a `CXXDefaultArgExpr`, and the expression on the parameter declaration is what has the `MaterializeTemporaryExpr`. It looks like we now have cases where different call sites require different semantics (and perhaps different diagnostics, somewhat like template instantiations).

This PR https://reviews.llvm.org/D136554 adds some machinery to rewrite `CXXDefaultArgExpr` when they are used, so we could, if needed, reuse that machinery to inject `MaterializeTemporaryExpr` (as part of D136554 <https://reviews.llvm.org/D136554> the rewrite only happen in the presence of immediate function calls)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D139586



More information about the cfe-commits mailing list