[clang] [C] Disable use of NRVO (PR #101038)

John McCall via cfe-commits cfe-commits at lists.llvm.org
Mon Jul 29 13:27:27 PDT 2024


rjmccall wrote:

> > C++ does have some restrictions on accessing objects that are being initialized through other names. It's possible that they're strong enough to satisfy the ABI rule here through a sort of reverse of the normal analysis: basically, any program that would violate the ABI rule is actually incorrect because of the semantic restriction. If not, I think we may need to force copies of trivial return types in the caller in C++. We can consider that separately, though.
> 
> I suspect it isn't legal to actually access the object through another pointer while it's being constructed, but that doesn't help if the user is just doing a pointer equality comparison.

Ah, good point.

> And C++17 rules forbid a copy on the caller side: "guaranteed copy elision" means semantically, there is no copy.

An extra copy is permitted for trivially-copyable types; otherwise we'd be required to pass and return all classes indirectly.

https://github.com/llvm/llvm-project/pull/101038


More information about the cfe-commits mailing list