BackendUtil's EmitAssemblyHelper::EmitAssembly generated call in wrong order

I think this is a problem with your expectations

The code in your main function is evalualated equivalent like this.

((std::cout << "return: ") << bar()) << std::endl;

The << operators are evaluated left to right one at a time. Just as they would be in the case of something like “foo() + bar() + baz()”

The << operator for cout prints and then return a reference to its left hand side so that multiple << can be chained together. Due to that, another way to write this is:

std::cout << "return: ";
std::cout << bar();
std::cout << std::endl;

Hi Craig,

Thanks for your response!

But GCC generated call in my expected order https://bugs.llvm.org/show_bug.cgi?id=35737#c1

Yes, it is my problem, I can write compatible and correct code like:

int r = bar();

std::cout << "return:" << r << std::endl;