2

From the MSDN:

Ty atomic<Ty>::operator++(int) volatile _NOEXCEPT;
Ty atomic<Ty>::operator++(int) _NOEXCEPT;
Ty atomic<Ty>::operator++() volatile _NOEXCEPT;
Ty atomic<Ty>::operator++() _NOEXCEPT;

The first two operators return the incremented value; the last two operators return the value before the increment.

But, C++11 documentation defines returns from this operators as

The value of the atomic variable after the modification. Formally, the result of incrementing/decrementing the value immediately preceding the effects of this function in the modification order of *this.

Why MSVC++ compiler use non standard definitions ?

23W
  • 1,413
  • 18
  • 37

1 Answers1

4

It's a documentation error on MSDN. This test program (LIVE):

#include <atomic>
#include <iostream>

template <typename T>
void foo(T&& t) {
    std::cout << ++t << '\n';
    std::cout << t++ << '\n';
    std::cout << static_cast<int>(t) << '\n';
}

int main()
{
    foo(0);
    foo(std::atomic<int>{0});
}

correctly outputs:

1
1
2
1
1
2

when compiled by VS2013.

Casey
  • 41,449
  • 7
  • 95
  • 125