<html>
    <head>
      <base href="https://bugs.llvm.org/">
    </head>
    <body><table border="1" cellspacing="0" cellpadding="8">
        <tr>
          <th>Bug ID</th>
          <td><a class="bz_bug_link 
          bz_status_NEW "
   title="NEW - Templated lambdas crashing the complier"
   href="https://bugs.llvm.org/show_bug.cgi?id=52508">52508</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>Templated lambdas crashing the complier
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>clang
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>12.0
          </td>
        </tr>

        <tr>
          <th>Hardware</th>
          <td>PC
          </td>
        </tr>

        <tr>
          <th>OS</th>
          <td>Linux
          </td>
        </tr>

        <tr>
          <th>Status</th>
          <td>NEW
          </td>
        </tr>

        <tr>
          <th>Severity</th>
          <td>normal
          </td>
        </tr>

        <tr>
          <th>Priority</th>
          <td>P
          </td>
        </tr>

        <tr>
          <th>Component</th>
          <td>C++17
          </td>
        </tr>

        <tr>
          <th>Assignee</th>
          <td>unassignedclangbugs@nondot.org
          </td>
        </tr>

        <tr>
          <th>Reporter</th>
          <td>ogito12311@gmail.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>blitzrakete@gmail.com, erik.pilkington@gmail.com, llvm-bugs@lists.llvm.org, richard-llvm@metafoo.co.uk
          </td>
        </tr></table>
      <p>
        <div>
        <pre>Here's some simplified code that exemplifies the problem.

int test(int x, int y)
{
    auto test_lambda_impl2 = [&]<int f, int z>()
    {
        if constexpr((f + z) < 3)
        {
            cout << f+z << endl;
        }
    };

    auto test_lambda_impl1 = [&]<int f>(int z)
    {
        switch(z)
        {
            case 0:
                test_lambda_impl2.operator()<f, 0>();
                break;
            case 1:
                test_lambda_impl2.operator()<f, 1>();
                break;
            case 2:
                test_lambda_impl2.operator()<f, 2>();
                break;
        }
    };

    switch(x)
    {
        case 0:
            test_lambda_impl1.operator()<0>(y);
            break;
        case 1:
            test_lambda_impl1.operator()<1>(y);
            break;
        case 2:
            test_lambda_impl1.operator()<2>(y);
            break;
    }
}

This just straight up crashes the compiler, if I remove test_lambda_impl2 and
just do something in test_lambda_impl1 instead, the code compiles but I get an
Invalid instruction exception or a segfault, depending on the code.

Clangd breaks when it has to parse this kind of code as well.

For reference, g++ works as expected.</pre>
        </div>
      </p>


      <hr>
      <span>You are receiving this mail because:</span>

      <ul>
          <li>You are on the CC list for the bug.</li>
      </ul>
    </body>
</html>