[clang] [Clang] Rebuild lambda captures in default member initializers while skipping body (PR #196597)

Eli Friedman via cfe-commits cfe-commits at lists.llvm.org
Tue Jun 30 11:47:00 PDT 2026


================
@@ -0,0 +1,23 @@
+// RUN: %clang_cc1 -std=c++20 -fsyntax-only -verify %s
+
+struct Noisy {
+  int x;
+  consteval Noisy(int x) : x(x) {}
+  ~Noisy() {}
+};
+
+struct Function {
+  template <typename F> Function(F) {}
+};
+
+struct Options {
+  int x;
+  Function function{ // expected-note {{declared here}}
+      // expected-error at +2 {{call to consteval function}}
+      // expected-note at +1 {{implicit use of 'this' pointer is only allowed within the evaluation of a call to a 'constexpr' member function}}
----------------
efriedma-quic wrote:

This error message doesn't look right.  The implicit use of "this" should be allowed here; if you replace the call to foo() with a constant, we should accept.  `this` refers to the object being constructed.

I guess that isn't specific to lambdas, though; I'm okay with opening a followup bug.  Compare the following with clang vs. gcc:

```
struct Noisy {
  int x;
  consteval Noisy(int x) : x(x) {}
  constexpr ~Noisy() {}
};

struct Function {
  template <typename F> constexpr Function(F) {}
};

struct Options {
  int x;
  Function function{Noisy{x}};
};

int foo();
Options kOptions{5};
```

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


More information about the cfe-commits mailing list