Compiler: Visual C++ 2012 RTM
Bug or not?: https://connect.microsoft.com/VisualStudio/feedback/details/763601/visual-c-2012-rtm-serious-compiler-bug
To me it seems weird it would inline calling test() into the second std::cout statement.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Yes. The compiler is free to make changes that are undetectable to the program. Since the
testfunction has no externally-visible effects, the compiler is free to make it as early or late as it wishes, or even eliminate it entirely.If you can explain some way this optimization made your code do something it shouldn’t do, then you have something. But so far, your only claim is that it made your code run slower or faster. The compiler is free to make optimizations that make some parts of your code slower and some parts faster. In fact, that’s the essence of optimization — making performance tradeoffs that we hope will generate a net gain. That may result in poor quality generated code, though in this case it doesn’t seem to, but it’s most certainly valid. That’s what optimization is all about.
A compiler takes your source code and produces output compiled code. It is free to build any compiled code it likes so long as it produces the observable results your source code asks it to produce. It is not required to produce the output the same way your source code does if it can find a way to produce the same effects in a way that it thinks is better. This is the whole point of optimization — to not do literally what you asked it to do but to produce the same results some other, hopefully better, way.