title: Googletest (gtest) / googlemock (gmock): Why is "interleav[ing] `EXPECT_CALL()`s and calls to the mock functions" undefined behavior?
body: <p>Despite writing</p>
  
  <ul>
  <li>this answer(<a href="https://stackoverflow.com/questions/44034633/google-mock-can-i-call-expect-call-multiple-times-on-same-mock-object/60905880#60905880">google mock - can I call EXPECT_CALL multiple times on same mock object?</a>)</li>
  <li>this answer (<a href="https://stackoverflow.com/questions/40089204/interleaving-expect-calls-and-calls-to-the-mock-functions/61467271#61467271">Interleaving EXPECT_CALL()s and calls to the mock functions</a>)</li>
  <li>and this issue (<a href="https://github.com/google/googletest/issues/2828#issuecomment-620222796" rel="nofollow noreferrer">Is interleaving <code>EXPECT_CALL()</code>s and calls to the mock function <em>really</em> undefined behavior?</a>)</li>
  </ul>
  
  <p>...I still don't know why Google says this is undefined behavior:</p>
  
  <blockquote>
    <p>...otherwise the behavior is undefined. In particular, you mustn't interleave EXPECT_CALL()s and calls to the mock functions" (<a href="https://github.com/google/googletest/blob/master/googlemock/docs/for_dummies.md#using-mocks-in-tests" rel="nofollow noreferrer">https://github.com/google/googletest/blob/master/googlemock/docs/for_dummies.md#using-mocks-in-tests</a>)</p>
  </blockquote>
  
  <p>They simply glossed over my issue above, restating it was in fact undefined behavior, but without explaining why.</p>
  
  <p>Can anyone explain the details of why and how it is undefined behavior? </p>