According to this Wiki page the following code:
#include <iostream>
struct C {
C() = default;
C(const C&) { std::cout << "A copy was made.\n"; }
};
C f() {
return C();
}
int main() {
std::cout << "Hello World!\n";
C obj = f();
}
may produce different outputs depending on the compiler and that compiler's settings.
How can I write programs if I cannot predict how they're going to behave (I cannot really know what any given compiler in any given version with any given settings will or will not optimize away)? Are there any general guidelines regarding copy-elision that I should follow?