Search code examples
c++debuggingc++17clion

Program exits with status code 0 in the middle of the execution in debug


I've reduced my program to the absolute minimum, and seem to have a weird bug in debug mode (it works in release mode). Whenever I set a breakpoint on the line auto* buckets = new Temp[bucket_count];, Clion exits with Process finished with exit code 0 within a half of a second after stopping at the line. No more lines of code are executed after this.

However, if I comment out the lambda const auto GetBucketIndex = ...;, the breakpoint stops as it should and I can continue to step through my program (this behaviour is the same for both this example and my non-reduced program). Removing the template and replacing it with int also removes the bug.

My initial thought was that I had some undefined behaviour somewhere, but I cannot see that there would be any. What could be the issue? Is this a bug with Clion perhaps? I've had the same problem with an other networking project of mine.

#include <cstdio>

struct Temp
{
    int hello;
};


template <class T>
void BucketSort(T* array, size_t count, size_t bucket_count)
{
    auto* buckets = new Temp[bucket_count];
    const auto GetBucketIndex = [](int element, size_t bucket_count) { return size_t((element / 9.0001f) * bucket_count); };
}


int main()
{
    printf("BucketSort:     ");
    int array[10] = {6, 3, 2, 0, 1, 5, 8, 7, 9, 4};
    BucketSort(array, 10, 3);
}

Solution

  • CLion bug report submitted by OP

    Original answer (prompting OP to open the bug report)

    You program is well-formed, and this is very likely a bug in CLion's debugger subsystem, to which there are already several similar open bug reports:

    Many of the open tickets have in common their lack of details or a minimal reproducible example. As you do, however, have a neat such example, you may want to submit a bug report on the debugger subsystem.


    There are, however, a few closed arguably related tickets

    The investigation and resolution of the latter, which relates to debugging with lldb, is particularly interesting:

    Maxim Banaev commented 29 Feb 2020 00:44:

    Broken in CLIon 2019.1.4

    Works fine in CLion 2019.2.5( #CL-192.7142.39) and later versions.

    In case you are also using lldb, you may want to try to reproduce your own problem with CLion 2019.2.5 or later prior to submitting your own report.