[clang] [clang] Add new warning: not eliding copy on return (missed NRVO) (PR #139973)

Grigory Pastukhov via cfe-commits cfe-commits at lists.llvm.org
Thu May 15 15:22:28 PDT 2025


grigorypas wrote:

> Can you also include a few tests which show whether we suppress the warning on disabled branches of an 'if constexpr'?
> 
> Beware we also have bugs and odd cases in this area:
> 
> * It should be possible to NRVO a variable which you don't actually return, by retuning it only on disabled branches.
>   It would be interesting to see what the warning does in this case.
> * You can generate bad code by returning a variable with the wrong type from a disabled branch.

I added several tests with dead branches. I noticed that Clang missed NRVO opportunity in create_object5 test. I wonder if it is a know issue or not. GCC seems to handle it. 

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


More information about the cfe-commits mailing list