steakhal wrote: To me the more interesting case is if we have side-effects in the constructor. https://godbolt.org/z/jPEa4sfeM The compiler is allowed to elide everything that doesn't violate the as-if rule. Consequently, both GCC and clang are right, and it doesn't matter if we emit or not emit reads from the freshly declaerd variable while its getting initialized. So we may as well also just elide it.
To me, it doesn't matter if it's C or C++. What matters is if it has side-effect or not. That said, we can just take the constructor decl and check if it's trivial. If so, we can elide; otherwise we can't. https://github.com/llvm/llvm-project/pull/187530 _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
