<div dir="ltr"><div>I actually didn't see any error when I simply converted it to unique_ptr and removed the dtor, so I'm wondering what error you saw. In any case, doesn't this work?</div><div><br></div><div>diff --git a/ELF/InputFiles.cpp b/ELF/InputFiles.cpp</div><div>index 497f946..01f8be9 100644</div><div>--- a/ELF/InputFiles.cpp</div><div>+++ b/ELF/InputFiles.cpp</div><div>@@ -43,7 +43,7 @@ template <class ELFT> DIHelper<ELFT>::DIHelper(elf::InputFile *F) {</div><div>     return;</div><div><br></div><div>   DWARFContextInMemory Dwarf(*Obj.get());</div><div>-  DwarfLine = new DWARFDebugLine(&Dwarf.getLineSection().Relocs);</div><div>+  DwarfLine.reset(new DWARFDebugLine(&Dwarf.getLineSection().Relocs));</div><div>   DataExtractor lineData(Dwarf.getLineSection().Data,</div><div>                          ELFT::TargetEndianness == support::little,</div><div>                          ELFT::Is64Bits ? 8 : 4);</div><div>@@ -53,7 +53,7 @@ template <class ELFT> DIHelper<ELFT>::DIHelper(elf::InputFile *F) {</div><div>   DwarfLine->getOrParseLineTable(lineData, 0);</div><div> }</div><div><br></div><div>-template <class ELFT> DIHelper<ELFT>::~DIHelper() { delete DwarfLine; }</div><div>+template <class ELFT> DIHelper<ELFT>::~DIHelper() {}</div><div><br></div><div> template <class ELFT> std::string DIHelper<ELFT>::getLineInfo(uintX_t Offset) {</div><div>   DILineInfo LineInfo;</div><div>diff --git a/ELF/InputFiles.h b/ELF/InputFiles.h</div><div>index a1a63b8..6c0f5cb 100644</div><div>--- a/ELF/InputFiles.h</div><div>+++ b/ELF/InputFiles.h</div><div>@@ -58,7 +58,7 @@ public:</div><div>   std::string getLineInfo(uintX_t Offset);</div><div><br></div><div> private:</div><div>-  llvm::DWARFDebugLine *DwarfLine = nullptr;</div><div>+  std::unique_ptr<llvm::DWARFDebugLine> DwarfLine;</div><div> };</div><div><br></div><div> // The root class of input files.</div></div><div class="gmail_extra"><br><div class="gmail_quote">On Tue, Oct 25, 2016 at 11:35 AM, Eugene Leviant <span dir="ltr"><<a href="mailto:evgeny.leviant@gmail.com" target="_blank">evgeny.leviant@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">I might not be catching your idea, but if you have the following line<br>
in InputFiles.h:<br>
<br>
std::unique_ptr<<wbr>DWARFDebugLine> DwarfLine;<br>
<br>
you will either have to:<br>
a) #include <llvm/DebugInfo/<wbr>DWARFDebugLine.h><br>
or<br>
b) std::unique_ptr<<wbr>DWARFDebugLine, MyDeleter> DwarfLine;<br>
<br>
This is because std::default_deleter<T> checks sizeof(T) in<br>
static_assert (where T is DWARFDebugLine)<br>
<div class="HOEnZb"><div class="h5"><br>
2016-10-25 21:26 GMT+03:00 Rui Ueyama <<a href="mailto:ruiu@google.com">ruiu@google.com</a>>:<br>
> On Tue, Oct 25, 2016 at 11:08 AM, Eugene Leviant <<a href="mailto:evgeny.leviant@gmail.com">evgeny.leviant@gmail.com</a>><br>
> wrote:<br>
>><br>
>> evgeny777 added inline comments.<br>
>><br>
>><br>
>> ================<br>
>> Comment at: ELF/InputFiles.cpp:56<br>
>> +<br>
>> +template <class ELFT> DIHelper<ELFT>::~DIHelper() { delete DwarfLine; }<br>
>> +<br>
>> ----------------<br>
>> ruiu wrote:<br>
>> > Use unique_ptr to remove this dtor.<br>
>> It's not possible unless you include DWARFContext.h to InputFiles.h or<br>
>> override unique_ptr deleter (second template parameter). Is this better?<br>
><br>
><br>
> You can have an empty dtor in InputFiles.cpp like `template <class ELFT><br>
> DIHelper<ELFT>::~DIHelper() {}` to write a definition of the dtor in the cpp<br>
> file instead of in the header so that you don't need to include the<br>
> DWARFContext.h, can't you?<br>
</div></div></blockquote></div><br></div>