[LLVMdev] StringMap question

Sanjoy Das sanjoy at playingwithpointers.com
Sat Jul 11 12:03:15 PDT 2015


On Sat, Jul 11, 2015 at 5:41 AM, Valery Pushkar <pollnossa at gmail.com> wrote:
> Hello everyone!
>
> I'm a newcomer for the great LLVM project. I've started to explore the
> source code of LLVM project to become more familiar with it, and I've found
> some strange usage of move semantics in constructor of
> StringMapImpl(StringMapImpl &&RHS) {...} class in
> include/llvm/ADT/StringMap.h line 56. Could anyone explain me the purpose of
> zeroing of all fields of RHS in the body of this constructor if the
> declaration of the constructor uses move semantics? Here is the consturctor
> code below:

I'm not a C++ expert, but this looks like a basic
move-constructor'ism.  We know that RHS is not going to be used after
the move constructor has run, so we steal the memory (TheTable and
related metadata) into *this.  Zeroing out the fields ensures that
when the destructor of RHS runs, it won't try to delete memory that
*this will use from now on.

Does that answer your question?

-- Sanjoy



More information about the llvm-dev mailing list