Is it legal for a C++0x compiler to optimize
int func(int&& a){
a = 3;
return a;
}
to
int func(int&& a){
return 3;
}
?
(or for another POD)
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.
Not like that per se, because the function must modify the variable
ato be equivalent. That said, after inlining and a bit of trivial optimization the result will be the same:Note the result is the same as if you used the second definition of
funcand inlined, only because the temporary variable wasn’t used. This shows that the two functions aren’t equivalent in general: