Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

warning: catching polymorphic type ‘class boost::thread_resource_error’ by value #5

Open
martindorey opened this issue Feb 17, 2024 · 0 comments

Comments

@martindorey
Copy link

A simple test:

martind@stormy:~/tmp/D158494$ cat polymorphic-catch.cpp 
#include "boost/threadpool/pool.hpp"

void* po = new boost::threadpool::pool;
martind@stormy:~/tmp/D158494$ 

... produces a warning when compiled with -Wall:

martind@stormy:~/tmp/D158494$ gcc -I ~/download/threadpool/ -c polymorphic-catch.cpp -Wall
In file included from /home/martind/download/threadpool/boost/threadpool/pool.hpp:27,
                 from polymorphic-catch.cpp:1:
/home/martind/download/threadpool/boost/threadpool/./detail/pool_core.hpp: In instantiation of ‘bool boost::threadpool::detail::pool_core<Task, SchedulingPolicy, SizePolicy, SizePolicyController, ShutdownPolicy>::resize(size_t) volatile [with Task = boost::function0<void>; SchedulingPolicy = boost::threadpool::fifo_scheduler; SizePolicy = boost::threadpool::static_size; SizePolicyController = boost::threadpool::resize_controller; ShutdownPolicy = boost::threadpool::wait_for_all_tasks; size_t = long unsigned int]’:
/home/martind/download/threadpool/boost/threadpool/size_policies.hpp:75:7:   required from ‘static void boost::threadpool::static_size<Pool>::init(Pool&, size_t) [with Pool = boost::threadpool::detail::pool_core<boost::function0<void>, boost::threadpool::fifo_scheduler, boost::threadpool::static_size, boost::threadpool::resize_controller, boost::threadpool::wait_for_all_tasks>; size_t = long unsigned int]’
/home/martind/download/threadpool/boost/threadpool/pool.hpp:103:29:   required from ‘boost::threadpool::thread_pool<Task, SchedulingPolicy, SizePolicy, SizePolicyController, ShutdownPolicy>::thread_pool(size_t) [with Task = boost::function0<void>; SchedulingPolicy = boost::threadpool::fifo_scheduler; SizePolicy = boost::threadpool::static_size; SizePolicyController = boost::threadpool::resize_controller; ShutdownPolicy = boost::threadpool::wait_for_all_tasks; size_t = long unsigned int]’
polymorphic-catch.cpp:3:35:   required from here
/home/martind/download/threadpool/boost/threadpool/./detail/pool_core.hpp:353:11: warning: catching polymorphic type ‘class boost::thread_resource_error’ by value [-Wcatch-value=]
           catch(thread_resource_error)
           ^~~~~
martind@stormy:~/tmp/D158494$ 

... on a gcc 8 from the Debian Buster era (2022), though it doesn't on gcc 6 from Debian Stretch (2020):

martind@stormy:~/tmp/D158494$ gcc -v
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-linux-gnu/8/lto-wrapper
OFFLOAD_TARGET_NAMES=nvptx-none
OFFLOAD_TARGET_DEFAULT=1
Target: x86_64-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Debian 8.3.0-6' --with-bugurl=file:///usr/share/doc/gcc-8/README.Bugs --enable-languages=c,ada,c++,go,brig,d,fortran,objc,obj-c++ --prefix=/usr --with-gcc-major-version-only --program-suffix=-8 --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-bootstrap --enable-clocale=gnu --enable-libstdcxx-debug --enable-libstdcxx-time=yes --with-default-libstdcxx-abi=new --enable-gnu-unique-object --disable-vtable-verify --enable-libmpx --enable-plugin --enable-default-pie --with-system-zlib --with-target-system-zlib --enable-objc-gc=auto --enable-multiarch --disable-werror --with-arch-32=i686 --with-abi=m64 --with-multilib-list=m32,m64,mx32 --enable-multilib --with-tune=generic --enable-offload-targets=nvptx-none --without-cuda-driver --enable-checking=release --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=x86_64-linux-gnu
Thread model: posix
gcc version 8.3.0 (Debian 8.3.0-6) 
martind@stormy:~/tmp/D158494$ 
martindorey added a commit to martindorey/threadpool that referenced this issue Feb 17, 2024
… by const reference to fix gcc-8's warning: catching polymorphic type ‘class boost::thread_resource_error’ by value (philipphenkel#5).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant