0

I have a feeling I might be asking the wrong question here.

I'm trying to compile the following code on MacOS in QtCreator using C++20:

#include <iostream>
#include <atomic>

struct A {
    int x;
    int y;
    int z;
};

int main()
{
    std::atomic<A> a;

    std::cout << std::boolalpha;
    std::cout << a.is_always_lock_free << std::endl;

    return 0;
}

Using the following .pro file:

CONFIG += c++20

SOURCES += \
        main.cpp

Following answers in the comments, I changed to using C++17, so CONFIG += c++17. This subsequently fixed the issue.

However I still get the following compilation error when compiling with C++20:

No member named 'is_always_lock_free' in 'std::atomic<A>'

Is this therefore an issue with QtCreator?

I tried adding the linker flag -latomic but that didn't help (I didn't think it would since this is a member variable not a function, but I thought I would try anyway).

For reference, this is my compile command:

clang++ -c -pipe -stdlib=libc++ -std=c++17 -Wall -Wextra -o main.o main.cpp

Which when used directly in the terminal (with the C++ standard set to c++20) compiles without error.

Is this member function missing from MacOS? There seems to be a lot of implementation defined behaviour on the cpp reference webpage.

For reference, I wanted to play around with this code on my Mac: `is_always_lock_free` gives `true` but `is_lock_free()` gives `false` on macOS, why?

HarryP2023
  • 298
  • 1
  • 13

0 Answers0