http://gcc.gnu.org/bugzilla/show_bug.cgi?id=51231
Bug #: 51231 Summary: g++ remove placement new with -O1 Classification: Unclassified Product: gcc Version: unknown Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ AssignedTo: unassig...@gcc.gnu.org ReportedBy: dushis...@mail.ru If code bellow compile with -O1 it prints '0', while with '-O0' it prints deadbeaf. The problem in allocator.construct (allocator.address (at), value); In boost_1_46_1/boost/interprocess/allocators/allocator.hpp it looks like: void construct(const pointer &ptr, const_reference v) { new((void*)detail::get_pointer(ptr)) value_type(v); } if rewrite it for example in such way: void construct(const pointer &ptr, const_reference v) { static volatile value_type *myp; myp = detail::get_pointer(ptr); ::new((void *)myp) value_type(v); } the code print expected value: deadbeaf. #include <iostream> #include <boost/interprocess/allocators/allocator.hpp> #include <boost/interprocess/managed_shared_memory.hpp> namespace interp = boost::interprocess; struct interp_memory_chunk { interp::managed_shared_memory chunk; interp_memory_chunk () { interp::shared_memory_object::remove ("GCC_interprocess_test"); chunk = interp::managed_shared_memory (interp::create_only, "GCC_interprocess_test", 0x10000); } ~interp_memory_chunk () { interp::shared_memory_object::remove ("GCC_interprocess_test"); } }; typedef interp::allocator <int, interp::managed_shared_memory::segment_manager> allocator_type; inline void create (allocator_type& allocator, allocator_type::value_type& at, int value) { allocator.construct (allocator.address (at), value); } int main () { interp_memory_chunk memory; allocator_type allocator (memory.chunk.get_segment_manager ()); allocator_type::pointer data = allocator.allocate (1); create (allocator, *data, 0xdeadbeef); std::cout << std::hex << *data << "\n"; }