Source: boost1.74
Version: 1.74.0+ds1-20
Severity: important
Tags: patch
When using asio, one may encounter an error when the header
"boost/asio/awaitable.hpp" is used that shows that std::exchange symbol cannot
be found. To reproduce this issue, one can use the daytime udp example from
boost.org[1] using the following meson.build file:
,----
| project('daytime', 'cpp',
| default_options : ['cpp_std=c++20'])
|
| boost_dep = dependency('boost')
| default_cpp_args = ['-ggdb3', '-O2', '-Wall']
|
| executable(
| 'daytime_udp_client',
| sources : 'daytime_udp_client.cpp',
| cpp_args : default_cpp_args,
| dependencies : [
| boost_dep
| ],
| )
`----
And build using "meson setup builddir && cd builddir && meson compile -v". The
error message is as follows:
,----
| -*- mode: compilation; default-directory:
"/sudo:root@localhost|docker:xiyueden@programming_learning_cpp_run_e19d94e6c210:/home/xiyueden/cpp/asio/daytime/builddir/"
-*-
| Compilation started at Mon May 22 01:49:57
|
| cd builddir && meson compile -v
| INFO: autodetecting backend as ninja
| INFO: calculating backend command to run: /bin/ninja -v
| [1/2] c++ -Idaytime_udp_client.p -I. -I.. -I/usr/include
-fdiagnostics-color=always -D_FILE_OFFSET_BITS=64 -Wall -Winvalid-pch
-std=c++20 -O0 -g -DBOOST_ALL_NO_LIB -ggdb3 -O2 -Wall -MD -MQ
daytime_udp_client.p/daytime_udp_client.cpp.o -MF
daytime_udp_client.p/daytime_udp_client.cpp.o.d -o
daytime_udp_client.p/daytime_udp_client.cpp.o -c ../daytime_udp_client.cpp
| FAILED: daytime_udp_client.p/daytime_udp_client.cpp.o
| c++ -Idaytime_udp_client.p -I. -I.. -I/usr/include -fdiagnostics-color=always
-D_FILE_OFFSET_BITS=64 -Wall -Winvalid-pch -std=c++20 -O0 -g -DBOOST_ALL_NO_LIB
-ggdb3 -O2 -Wall -MD -MQ daytime_udp_client.p/daytime_udp_client.cpp.o -MF
daytime_udp_client.p/daytime_udp_client.cpp.o.d -o
daytime_udp_client.p/daytime_udp_client.cpp.o -c ../daytime_udp_client.cpp
| In file included from /usr/include/boost/asio.hpp:23,
| from ../daytime_udp_client.cpp:3:
| /usr/include/boost/asio/awaitable.hpp: In constructor
‘boost::asio::awaitable<T, Executor>::awaitable(boost::asio::awaitable<T,
Executor>&&)’:
| /usr/include/boost/asio/awaitable.hpp:68:19: error: ‘exchange’ is not a
member of ‘std’; did you mean ‘std::__atomic_impl::exchange’?
| 68 | : frame_(std::exchange(other.frame_, nullptr))
| | ^~~~~~~~
| In file included from /usr/include/c++/12/bits/shared_ptr_atomic.h:33,
| from /usr/include/c++/12/memory:78,
| from /usr/include/boost/asio/associated_allocator.hpp:19,
| from /usr/include/boost/asio.hpp:20:
| /usr/include/c++/12/bits/atomic_base.h:976:7: note:
‘std::__atomic_impl::exchange’ declared here
| 976 | exchange(_Tp* __ptr, _Val<_Tp> __desired, memory_order __m)
noexcept
| | ^~~~~~~~
| ninja: build stopped: subcommand failed.
|
| Compilation exited abnormally with code 1 at Mon May 22 01:49:59
`----
The GCC in use is the current in sid:
,----
| Using built-in specs.
| COLLECT_GCC=gcc
| COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-linux-gnu/12/lto-wrapper
| OFFLOAD_TARGET_NAMES=nvptx-none:amdgcn-amdhsa
| OFFLOAD_TARGET_DEFAULT=1
| Target: x86_64-linux-gnu
| Configured with: ../src/configure -v --with-pkgversion='Debian 12.2.0-14'
--with-bugurl=file:///usr/share/doc/gcc-12/README.Bugs
--enable-languages=c,ada,c++,go,d,fortran,objc,obj-c++,m2 --prefix=/usr
--with-gcc-major-version-only --program-suffix=-12
--program-prefix=x86_64-linux-gnu- --enable-shared --enable-linker-build-id
--libexecdir=/usr/lib --without-included-gettext --enable-threads=posix
--libdir=/usr/lib --enable-nls --enable-clocale=gnu --enable-libstdcxx-debug
--enable-libstdcxx-time=yes --with-default-libstdcxx-abi=new
--enable-gnu-unique-object --disable-vtable-verify --enable-plugin
--enable-default-pie --with-system-zlib --enable-libphobos-checking=release
--with-target-system-zlib=auto --enable-objc-gc=auto --enable-multiarch
--disable-werror --enable-cet --with-arch-32=i686 --with-abi=m64
--with-multilib-list=m32,m64,mx32 --enable-multilib --with-tune=generic
--enable-offload-targets=nvptx-none=/build/gcc-12-bTRWOB/gcc-12-12.2.0/debian/tmp-nvptx/usr,amdgcn-amdhsa=/build/gcc-12-bTRWOB/gcc-12-12.2.0/debian/tmp-gcn/usr
--enable-offload-defaulted --without-cuda-driver --enable-checking=release
--build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=x86_64-linux-gnu
| Thread model: posix
| Supported LTO compression algorithms: zlib zstd
| gcc version 12.2.0 (Debian 12.2.0-14)
`----
I have also tried different standard versions (11/14/17) and all shows the same
error.
The fix is to add "#include <utility>" in "boost/asio/awaitable.hpp". I'll
attach a patch. Note that the boost1.81 package already included this fix.
[1]
https://www.boost.org/doc/libs/1_74_0/doc/html/boost_asio/tutorial/tutdaytime4/src.html
-- System Information:
Debian Release: 12.0
APT prefers testing-security
APT policy: (500, 'testing-security'), (500, 'testing')
Architecture: amd64 (x86_64)
Kernel: Linux 6.1.0-9-amd64 (SMP w/16 CPU threads; PREEMPT)
Locale: LANG=en_US.UTF-8, LC_CTYPE=en_US.UTF-8 (charmap=UTF-8), LANGUAGE not set
Shell: /bin/sh linked to /usr/bin/dash
Init: systemd (via /run/systemd/system)
LSM: AppArmor: enabled
--- /usr/include/boost/asio/awaitable.hpp 2023-01-30 09:20:12.000000000
-0800
+++ /usr/include/boost/asio/awaitable.hpp.patched 2023-05-22
01:59:49.607095861 -0700
@@ -25,6 +25,7 @@
# include <experimental/coroutine>
#endif // defined(BOOST_ASIO_HAS_STD_COROUTINE)
+#include <utility>
#include <boost/asio/any_io_executor.hpp>
#include <boost/asio/detail/push_options.hpp>