Skip to main content
Stack Overflow
  1. About
  2. For Teams

Return to Question

Post Timeline

Split error from code
Source Link
user4581301
  • 34.1k
  • 7
  • 42
  • 65

I thought g++ 10.3 should have supported the C++20 feature of atomic shared_ptr? But I am still getting the following error

#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),
 | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
#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),
 | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~

I thought g++ 10.3 should have supported the C++20 feature of atomic shared_ptr? But I am still getting the following error

#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),
 | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~

I thought g++ 10.3 should have supported the C++20 feature of atomic shared_ptr? But I am still getting the following error

#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),
 | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
Source Link
Kenneth
  • 685
  • 1
  • 7
  • 17

gcc 10 support for atomic shared_ptr

I thought g++ 10.3 should have supported the C++20 feature of atomic shared_ptr? But I am still getting the following error

#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),
 | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
lang-cpp

AltStyle によって変換されたページ (->オリジナル) /