C++ Logo


Advanced search

Re: [std-proposals] C++ never had a compiler without a stack

From: David Brown <david_at_[hidden]>
Date: Fri, 18 Aug 2023 16:59:38 +0200
On 16/08/2023 16:20, Thiago Macieira via Std-Proposals wrote:
> On Wednesday, 16 August 2023 04:42:09 PDT David Brown via Std-Proposals wrote:
>> Some people argue that alloca() and VLAs are unsafe because there is no
>> way to get run-time feedback if the sizes are too big and you overflow
>> the stack - it's straight to UB.
> The fact that the implementations don't give feedback does not mean that they
> couldn't give feedback if they needed to. The bounds of the stack can be saved
> by the runtime in a thread-local variable.

That would certainly be possible on some platforms - but impossible to
implement on others. There would be nothing to stop alloca() being
specified as returning 0 if an overflow problem were detectable and
detected. You'd still have the risk of the alloca() using up almost all
of the stack, and then seeing a disaster on the next function call.

I can't see a suitable interface for having a VLA declaration give
feedback on stack overflow - just as there is no standardised way to
detect any other problems with local variable allocations on the stack.

Received on 2023-08-18 14:59:47