Trying to disable elide constructors for one function, the following function gives me the expected output under GCC, but not under clang. Under GCC, the output includes copy cstr called
as expected, but not under clang, which gives the warning: unknown attribute 'optimize' ignored [-Wattributes]
What could be happening? Should I be using anther keyword in place of 'optimize'?
#include <iostream>
class xyz {
public:
xyz() { std::cout << "cstr called\n"; }
xyz(const xyz& A) { std::cout << "copy cstr called\n"; }
xyz f() __attribute__((optimize("no-elide-constructors"))) {
std::cout << "f called\n";
xyz x;
return x;
}
};
int main() {
xyz a;
xyz b = a.f();
}