'What happens if you inline a function that calls it self in C++

First I thought the compile time would take forever, or I take a weird error, but that didn't happen. The code runs for a while and then crashes.

This is my code:

#include <iostream>

inline void say_hello()
{
    std::cout << "hello\n";
    say_hello();
}

int main()
{
    say_hello();
}

I thought the compiler will convert it to something like this:

#include <iostream>

int main()
{
    std::cout << "hello\n";
    std::cout << "hello\n";
    std::cout << "hello\n";
    std::cout << "hello\n";
    std::cout << "hello\n";
    std::cout << "hello\n";
    std::cout << "hello\n";
    std::cout << "hello\n";
    std::cout << "hello\n";
    std::cout << "hello\n";
    std::cout << "hello\n";
    std::cout << "hello\n";
    std::cout << "hello\n";
    std::cout << "hello\n";
    std::cout << "hello\n";
    // and crash because my storage is filled
}

But, I think the compiler ignored the inline keyword.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source