https://bugs.llvm.org/show_bug.cgi?id=52508

            Bug ID: 52508
           Summary: Templated lambdas crashing the complier
           Product: clang
           Version: 12.0
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: normal
          Priority: P
         Component: C++17
          Assignee: [email protected]
          Reporter: [email protected]
                CC: [email protected], [email protected],
                    [email protected], [email protected]

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.

-- 
You are receiving this mail because:
You are on the CC list for the bug.
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to