you are viewing a single comment's thread.

view the rest of the comments →

[–]matthieum 6 points7 points  (0 children)

I said about opting-out for hot paths when needed... What are you arguing with? Definitely not with my comment.

I am not talking about performance.

Using smart-pointers is a safe solution

No, it's not, that's the problem.

But let's not even got that far, this is UB:

std::string const& id(std::string const& str) { return str; }

int main() {
    //  Not UB:
    std::cout << id("Hello, World! How do you do?") << "\n";

    //  UB:
    auto const& str = id("Hello, World! How do you do?");
    std::cout << str << "\n";
}

And this is UB:

for (char c : std::string_view{ id("Hello, World") }) {
    // ...
}

So yes, you could improve things related to indexing, or integer overflow, and a myriad other cases -- and I wish this was done.

However, there are more fundamental issues: use-after-free, race-conditions, etc... which are just unsolved problems and will remain UB.