Armclang/Armcc是否支持复制消除?是否有类似GCC的禁用选项?
Great question—let's clear this up for you since it's not always obvious in the docs at first glance:
Do armclang/armcc support copy elision?
Absolutely! Both compilers fully support copy elision (including Return Value Optimization, RVO, and Named Return Value Optimization, NRVO) as required by the C++ standard. This optimization is enabled by default in release builds (and even most debug builds unless you explicitly disable optimizations).What are the equivalent flags to disable copy elision?
- For armclang: Since it's built on LLVM/Clang and maintains strong GCC compatibility, you can use the exact same flag as GCC:
-fno-elide-constructors. This will turn off all copy and move constructor elision. - For armcc (the legacy Arm compiler, now superseded by armclang), the equivalent flag is
--no_elide_constructors(note the double hyphens and underscore instead of hyphens).
- For armclang: Since it's built on LLVM/Clang and maintains strong GCC compatibility, you can use the exact same flag as GCC:
If you want to confirm these flags exist for your specific compiler version, you can run a quick help command like armclang --help | grep elide or armcc --help | grep elide to see the option listed directly.
内容的提问来源于stack exchange,提问作者Michael Guo

