Opened 4 years ago

Last modified 4 years ago

#13639 new Bugs

monotonic_buffer_resource current_buffer() possibly broken and documentation wrong

Reported by: Markus Dreseler Owned by: Ion Gaztañaga
Milestone: To Be Determined Component: container
Version: Boost 1.67.0 Severity: Problem
Keywords: Cc:

Description

The comment and the function declaration do not seem to match:

   //! <b>Returns</b>:
   //!   The number of bytes of storage available for the specified alignment.
   //!
   //! <b>Note</b>: Non-standard extension.
   const void *current_buffer() const BOOST_NOEXCEPT;

Source: https://www.boost.org/doc/libs/1_67_0/boost/container/pmr/monotonic_buffer_resource.hpp

Change History (1)

comment:1 by Markus Dreseler, 4 years ago

Severity: CosmeticProblem
Summary: Documentation of monotonic_buffer_resource looks wrongmonotonic_buffer_resource current_buffer() possibly broken and documentation wrong

Looking at this again, it looks like current_buffer itself is also broken. Instead of returning a pointer to the start of the current buffer, it returns a pointer to where the next allocation should go:

// clang++ -std=c++1z -lboost_container mbr.cpp

#include <boost/container/pmr/monotonic_buffer_resource.hpp>
#include <boost/container/pmr/polymorphic_allocator.hpp>
#include <iostream>

int main() {
	auto buffer = boost::container::pmr::monotonic_buffer_resource(size_t{100});
	auto allocator = boost::container::pmr::polymorphic_allocator<char>{&buffer};
	allocator.allocate(1);
	auto start_ptr = buffer.current_buffer();
	allocator.allocate(50);
	auto end_ptr = buffer.current_buffer();

	std::cout << (reinterpret_cast<uintptr_t>(end_ptr) - reinterpret_cast<uintptr_t>(start_ptr)) << std::endl;
	// prints 50, but should be 0
}

Using clang 6.0 on OSX with boost 1.67.0_1.

Note: See TracTickets for help on using tickets.