Opened 11 years ago

#5545 new Bugs

ptr_container: unused parameter warnings if exceptions and asserts disabled

Reported by: timb@… Owned by: Thorsten Ottosen
Milestone: To Be Determined Component: ptr_container
Version: Boost 1.39.0 Severity: Problem
Keywords: Cc:

Description

With exceptions and asserts both disabled, ptr_container_detail::reversible_ptr_container<>::enforce_null_policy() generates unused-parameter warnings. Both its parameters are used only within an invocation of BOOST_PTR_CONTAINER_THROW_EXCEPTION(); with exceptions disabled, that expands to a BOOST_ASSERT(); with asserts disabled, that in turn becomes just (void)0 (or equivalent).

One way to fix this would be to make BOOST_PTR_CONTAINER_THROW_EXCEPTION expand to BOOST_VERIFY instead of BOOST_ASSERT, so that the parameters are still evaluated even when exceptions and asserts are disabled. This should make no difference when exceptions are enabled, or when exceptions are disabled but asserts are enabled.

Minimal example:

$ cat test.cpp
#include <boost/ptr_container/ptr_vector.hpp>

void foo(int *p)
{
    boost::ptr_vector<int>().push_back(p);
}
$ g++ -W -Wall -fno-exceptions -Iboost -DNDEBUG -c test.cpp
In file included from boost/boost/ptr_container/ptr_sequence_adapter.hpp:20,
                 from boost/boost/ptr_container/ptr_vector.hpp:20,
                 from test.cpp:1:
boost/boost/ptr_container/detail/reversible_ptr_container.hpp: In instantiation of 'static void boost::ptr_container_detail::reversible_ptr_container<Config, CloneAllocator>::enforce_null_policy(const typename Config::value_type*, const char*) [with Config = boost::ptr_container_detail::sequence_config<int, std::vector<void*, std::allocator<void*> > >, CloneAllocator = boost::heap_clone_allocator]':
boost/boost/ptr_container/ptr_sequence_adapter.hpp:246:   instantiated from 'void boost::ptr_sequence_adapter<T, VoidPtrSeq, CloneAllocator>::push_back(typename boost::ptr_container_detail::reversible_ptr_container<boost::ptr_container_detail::sequence_config<T, VoidPtrSeq>, CloneAllocator>::value_type) [with T = int, VoidPtrSeq = std::vector<void*, std::allocator<void*> >, CloneAllocator = boost::heap_clone_allocator]'
test.cpp:5:   instantiated from here
boost/boost/ptr_container/detail/reversible_ptr_container.hpp:260: warning: unused parameter 'x'
boost/boost/ptr_container/detail/reversible_ptr_container.hpp:260: warning: unused parameter 'msg'

(g++ will not emit the warnings if the boost headers are found in the system include directories.)

Attachments (1)

ptr_container_throw_exception.patch (356 bytes ) - added by timb@… 11 years ago.
Suggested fix

Download all attachments as: .zip

Change History (1)

by timb@…, 11 years ago

Suggested fix

Note: See TracTickets for help on using tickets.