[cfe-dev] StringMap moves its Allocator. What happens with a reference?

Yaron Keren yaron.keren at gmail.com
Mon Nov 17 01:13:51 PST 2014


A common pattern is having one allocator serve several data structures, for
instance

 typedef StringMap<bool, BumpPtrAllocator&> SymbolTable;
 BumpPtrAllocator Allocator;
 SymbolTable Sym1;
 SymbolTable Sym2;
 Sym2 = std::move(Sym1);

With gcc 4.9.1 this fails

/llvm/include/llvm/ADT/StringMap.h:
  In instantiation of 'llvm::StringMap<ValueTy,
AllocatorTy>::StringMap(llvm::StringMap<ValueTy, AllocatorTy>&&)
  [with ValueTy = llvm::MCSymbol*; AllocatorTy =
llvm::BumpPtrAllocatorImpl<>&]':

/llvm/include/llvm/ADT/StringMap.h:243:74:
  error: invalid initialization of non-const reference of type
'llvm::BumpPtrAllocatorImpl<>&'
  from an rvalue of type
'std::remove_reference<llvm::BumpPtrAllocatorImpl<>&>::type {aka
llvm::BumpPtrAllocatorImpl<>}'
       : StringMapImpl(std::move(RHS)), Allocator(std::move(RHS.Allocator))
{}

due to the inability to move the allocator reference where in fact we wish
to copy it.

With Visual C++ 2013 the code compiles and apperantly copies the allocator
reference.

What is the proper way to move such StringMaps or other data structures
using an allocator reference?

Yaron
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20141117/17e0ea7d/attachment.html>


More information about the cfe-dev mailing list