libbitcoin / libbitcoin-system

Bitcoin Cross-Platform C++ Development Toolkit
https://libbitcoin.info/
Other
1.29k stars 381 forks source link

xcode: error: no matching 'operator new' for non-allocating placement new #1494

Closed evoskuil closed 1 month ago

evoskuil commented 2 months ago

xcode only: error: no matching 'operator new' function for non-allocating placement new expression; include <new>

Related bugs in llvm/clang are documented. The error states that include <new> is required, yet including this as the very first in define.hpp does not resolve.

In file included from src/chain/block.cpp:19:
In file included from ./include/bitcoin/system/chain/block.hpp:22:
  CXX      src/chain/libbitcoin_system_la-checkpoint.lo
In file included from /Applications/Xcode_15.0.1.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/c++/v1/functional:510:
In file included from /Applications/Xcode_15.0.1.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/c++/v1/__functional/bind.h:17:
In file included from /Applications/Xcode_15.0.1.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/c++/v1/tuple:211:
/Applications/Xcode_15.0.1.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/c++/v1/__memory/allocator_arg_t.h:57:5: error: no matching 'operator new' function for non-allocating placement new expression; include <new>
    new (__storage) _Tp (_VSTD::forward<_Args>(__args)...);
    ^~~
/Applications/Xcode_15.0.1.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/c++/v1/__memory_resource/polymorphic_allocator.h:117:10: note: in instantiation of function template specialization 'std::__user_alloc_construct_impl<const std::array<unsigned char, 6>, std::pmr::polymorphic_allocator<const std::array<unsigned char, 6>>>' requested here
    std::__user_alloc_construct_impl(
         ^
/Applications/Xcode_15.0.1.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/c++/v1/__memory/allocator_traits.h:296:13: note: in instantiation of function template specialization 'std::pmr::polymorphic_allocator<const std::array<unsigned char, 6>>::construct<const std::array<unsigned char, 6>>' requested here
        __a.construct(__p, _VSTD::forward<_Args>(__args)...);
            ^
/Applications/Xcode_15.0.1.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/c++/v1/__memory/shared_ptr.h:995:55: note: in instantiation of function template specialization 'std::__shared_ptr_emplace<const std::array<unsigned char, 6>, std::pmr::polymorphic_allocator<const std::array<unsigned char, 6>>>::__shared_ptr_emplace<>' requested here
    ::new ((void*)_VSTD::addressof(*__guard.__get())) _ControlBlock(__a, _VSTD::forward<_Args>(__args)...);
                                                      ^
./include/bitcoin/system/impl/data/memory.ipp:73:17: note: in instantiation of function template specialization 'std::allocate_shared<const std::array<unsigned char, 6>, std::pmr::polymorphic_allocator<const std::array<unsigned char, 6>>, void>' requested here
    return std::allocate_shared<const Type,
                ^
./include/bitcoin/system/impl/stream/streamers/byte_reader.ipp:259:23: note: in instantiation of function template specialization 'libbitcoin::system::to_allocated<std::array<unsigned char, 6>, std::pmr::memory_resource *>' requested here
    const auto cptr = to_allocated<data_array<Size>>(allocator_);
                      ^
./include/bitcoin/system/impl/stream/streamers/byte_reader.ipp:305:12: note: in instantiation of function template specialization 'libbitcoin::system::byte_reader<libbitcoin::system::istream<>>::read_forward_cptr<6UL>' requested here
    return read_forward_cptr<mini_hash_size>();
           ^
src/chain/block.cpp:87:11: note: in instantiation of member function 'libbitcoin::system::byte_reader<libbitcoin::system::istream<>>::read_mini_hash_cptr' requested here
  : block(read::bytes::fast(stream), witness)
          ^
  CXX      src/chain/libbitcoin_system_la-context.lo

https://github.com/libbitcoin/libbitcoin-system/actions/runs/9827836010/job/27131015644

evoskuil commented 2 months ago

https://stackoverflow.com/questions/2788388/when-is-include-new-library-required-in-c

evoskuil commented 2 months ago

After encountering this error:

https://bugreports.qt.io/browse/QTBUG-114316

Symbol not found: __ZNSt3__13pmr15memory_resourceD2Ev

See: https://developer.apple.com/xcode/cpp/ search for memory_resource...

<memory_resource> | P0220R1 | Requires Xcode 15Minimum deployment target: iOS 17.0, macOS 14.0, watchOS 10.0 and tvOS 17.0.

P0220R1](https://wg21.link/P0220R1/)
Requires Xcode 15

Minimum deployment target: iOS 17.0, macOS 14.0, watchOS 10.0 and tvOS 17.0.

We are on macOS-13...

2024-07-08T16:19:44.4836060Z Current runner version: '2.317.0'
2024-07-08T16:19:44.4863560Z ##[group]Operating System
2024-07-08T16:19:44.4864330Z macOS
2024-07-08T16:19:44.4864660Z 13.6.7
2024-07-08T16:19:44.4864970Z 22G807
2024-07-08T16:19:44.4865310Z ##[endgroup]
2024-07-08T16:19:44.4865700Z ##[group]Runner Image
2024-07-08T16:19:44.4866140Z Image: macos-13
2024-07-08T16:19:44.4866540Z Version: 20240630.1
2024-07-08T16:19:44.4867770Z Included Software: https://github.com/actions/runner-images/blob/macos-13/20240630.1/images/macos/macos-13-Readme.md
evoskuil commented 1 month ago

Worked around this by implementing own polymorphic allocator and memory resource (for other reasons).