Ken Y-N
Ken Y-N

Reputation: 15018

Can undefined behaviour cause an exception in a function defined as never throwing an exception?

I was looking at a description of delete[] and it says:

Exception safety
No-throw guarantee: this function never throws exceptions.

But it adds:

Notice that an invalid value of ptr causes undefined behavior.

I suspect that UB can include throwing an exception and the guarantee is only good for valid pointers, but I just thought I'd check.

Upvotes: 1

Views: 661

Answers (1)

Pete Becker
Pete Becker

Reputation: 76523

"Undefined behavior" means that the language definition does not tell you what the code does. So, yes, anything can happen, including blowing past a noexcept specifier. After all, there are no rules... (well, your compiler may provide rules, but relying on that is not portable).

Upvotes: 3

Related Questions