lambda with this auto that captures this in a member function is not an integral constant expression (original) (raw)

https://godbolt.org/z/azqxac8xE

struct S { int i = 42; constexpr auto f() { return [this](this auto) { return this->i; }(); }; };

static_assert(S().f() == 42);

Clang rejects the above code with:

<source>:10:15: error: static assertion expression is not an integral constant expression
   10 | static_assert(S().f() == 42);
      |               ^~~~~~~~~~~~~
<source>:5:14: note: use of 'this' pointer is only allowed within the evaluation of a call to a 'constexpr' member function
    5 |       return this->i;
      |              ^

If we remove this auto then compile fine, the two should be equivalent right?
Not really sure what the standards say about this.