[llvm-bugs] [Bug 52508] New: Templated lambdas crashing the complier

via llvm-bugs llvm-bugs at lists.llvm.org
Mon Nov 15 04:53:07 PST 2021


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: unassignedclangbugs at nondot.org
          Reporter: ogito12311 at gmail.com
                CC: blitzrakete at gmail.com, erik.pilkington at gmail.com,
                    llvm-bugs at lists.llvm.org, richard-llvm at metafoo.co.uk

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.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20211115/5341f563/attachment.html>


More information about the llvm-bugs mailing list