0

我以为 g++ 10.3 应该支持 atomic shared_ptr 的 C++20 特性?但我仍然收到以下错误

#include <atomic>
#include <thread>
#include <memory>

int main() {
  std::atomic<std::shared_ptr<int>> a = std::make_shared<int>(1);
}
In file included from test.cc:1:
/usr/include/c++/10/atomic: In instantiation of ‘struct std::atomic<std::shared_ptr<int> >’:
test.cc:6:37:   required from here
/usr/include/c++/10/atomic:195:21: error: static assertion failed: std::atomic requires a trivially copyable type
  195 |       static_assert(__is_trivially_copyable(_Tp),
      |                     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
4

1 回答 1

2

文档将其列为仅自 GCC 12.1 起支持,即下一个版本,并且编译器资源管理器显示您的代码在 GCC 主干上编译:https ://godbolt.org/z/4ThzMrjM9

https://gcc.gnu.org/onlinedocs/libstdc++/manual/status.html

于 2022-01-25T00:01:26.007 回答