title: this = nullptr in lambda functions gcc 11.1
body: <p>I've got the following code:</p>
  <pre><code>#include &lt;iostream&gt;
  
  template&lt;typename T&gt;
  struct A
  {
      T a;
      T b;
      static bool(*foo)(T, T);
  };
  
  template&lt;&gt;
  bool(*A&lt;int&gt;::foo)(int, int) = [](int a, int b)-&gt;bool{ return a == b; };
  
  struct B
  {
      int b;
  };
  
  template&lt;typename T, typename U&gt;
  T bar(U(*func)(const int&amp;)) { return func(23).b; }
  
  int main()
  {
      A&lt;int&gt; a = {.a=1, .b=1};
      std::cout &lt;&lt; std::boolalpha &lt;&lt; A&lt;int&gt;::foo(a.a, a.b) &lt;&lt; std::endl;
      std::cout &lt;&lt; bar&lt;int, B&gt;([](const int&amp; val) -&gt; B { return {.b = val}; });
      return 0;
  }
  </code></pre>
  <p>Being compiled with <code>-Werror=nonnull -Og -fsanitize=undefined -std=c++20</code> flags under gcc 11.1 it produces a error per lambda like:</p>
  <pre><code>&lt;source&gt;:12:71: error: 'this' pointer is null [-Werror=nonnull]
  </code></pre>
  <p>(for more details see <a href="https://godbolt.org/z/a4GsPW71E" rel="noreferrer">https://godbolt.org/z/a4GsPW71E</a>)</p>
  <p>As I know, <code>this = nullptr</code> is a vivid marker of UB in the code, however my code looks pretty inconspicuous. To avoid the error you should either change version of compiler or make a slight change in the code (e.g. remove lambda's parameter, or template, or something else).</p>
  <p>Does anyone know the reason of this errors, does gcc try to help me or it is just a bug in the compiler?</p>