HomePhabricator

Update atomic feature macros, synopsis, signatures to match C++20. Improve test…

Authored by __simt__ on Sep 9 2020, 10:00 AM.

Description

Update atomic feature macros, synopsis, signatures to match C++20. Improve test coverage for non-lock-free atomics.

Details

Committed
__simt__Sep 9 2020, 10:00 AM
Parents
rG4b15fc9ddb4d: [NFC][MLInliner] Don't initialize in an assert.
Branches
Unknown
Tags
Unknown

Event Timeline

miyuki added a subscriber: miyuki.Sep 11 2020, 7:24 AM

Hi Olivier,
Prior versions of the C++ standard (11, 14, 17) required more specialized templates for atomic_fetch_{add,sub}[_explicit] for pointers. E.g.:

template <class T>
T atomic_fetch_add(atomic<T>*, T) noexcept;
template <class T>
T* atomic_fetch_add(atomic<T*>*, ptrdiff_t) noexcept;

Implementing them as a single template breaks the following code (when compiled as C++17):

#include <atomic>

void test() {
    std::atomic<int*> a;
    std::atomic_fetch_add<int>(&a, 1);
}

Could you please partially revert this commit and use the previous implementation of atomic_fetch_{add,sub}[_explicit] and only use the new implementation when compiling as C++20 and later?

I will revert this part immediately, thanks for the heads up!

Also adding a test case.