What is error?

void g(auto x) { g(x - 1); }
Absence of declared type for the argument of the function.

Absence of any means of stopping the recursion.

Absence of any context.
Probably an infinite loop.

g(2) call g(1)

g(1) call g(0)

g(0) call g(-1) etc...

You should put something like this :
 
if(!x) return;
Last edited on
There is no error.
1
2
3
4
5
6
void g(auto x) { g(x - 1); }

int main()
{

}

This code gives me no error.
I got
test.cpp:1:8: warning: use of 'auto' in parameter declaration only available with -fconcepts
 void g(auto x) { g(x - 1); }


Go on, stick the line
g(10);
in the middle of int main() and find out how big the stack is(n't).
Last edited on
Well funny you should mention that, if you compile with -O3, I believe g++ does tail-call optimization, and it doesn't crash for me.

But even without a stack overflow, the program will have undefined behavior once x - 1 underflows after being the lowest int possible.
Topic archived. No new replies allowed.