This code
#include <iostream>
#include <map>
int main()
{
std::map<int, std::size_t> m;
m[0] = m.size();
std::cout << m[0] << std::endl;
}
will print 0
with vc++ and 1
with g++.
1
. How does vc++ end up with 0
?Since C++17 the order of evaluation is guaranteed, m.size()
is sequenced before m[0]
; the result is guaranteed to be 0
.
- In every simple assignment expression E1=E2 and every compound assignment expression E1@=E2, every value computation and side-effect of E2 is sequenced before every value computation and side effect of E1
Before C++17 the behavior is unspecified.
BTW you can observe different behaviors with Gcc C++17 mode and Gcc C++14 mode.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With