[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

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

With gcc 4.9.1 this fails

  In instantiation of 'llvm::StringMap<ValueTy,
AllocatorTy>::StringMap(llvm::StringMap<ValueTy, AllocatorTy>&&)
  [with ValueTy = llvm::MCSymbol*; AllocatorTy =

  error: invalid initialization of non-const reference of type
  from an rvalue of type
'std::remove_reference<llvm::BumpPtrAllocatorImpl<>&>::type {aka
       : 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

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

-------------- 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