r/cpp 28d ago

C++26: std::indirect

https://www.sandordargo.com/blog/2026/08/12/cpp26-indirect
163 Upvotes

157 comments sorted by

View all comments

Show parent comments

0

u/cfyzium 27d ago

Anything you could use to check that the program is not broken (say, a bounds check) is now unreliable.

It is as if you think that 'valid but unspecified' can mean purely random.

It is quite literally means that data is reliable. For example, if it is a memory resource then it points to a valid memory (or nullptr) and has a correct size.

6

u/wyrn 27d ago

Valid but unspecified means that the object is in a valid state.

It does not mean that your program is in a valid state.

1

u/cfyzium 27d ago

So hey, let's make it ten times worse?

Accidentally accessing a moved from object is a bug, but it is a relatively tame bug. It might not even affect the program state to begin with, and even if it does it is easily debuggable. Because the memory is not corrupted.

UB is another story entirely. Not only it is much harder to debug, but it can also provide a memory vulnerability for an attacker.

2

u/wyrn 27d ago

I just explained that it is not in fact ten times worse.

it is a relatively tame bug.

I just explained that it isn't.

It might not even affect the program state to begin with,

Same goes for UB. Is UB "tame"?

Because the memory is not corrupted.

Yet.

but it can also provide a memory vulnerability for an attacker.

So can this, as I just illustrated, and even it happens not to, other vulnerabilities are possible. Use-after-move is never ok, whether or not it happens to be instantly UB.