<div dir="ltr">Yes, but that error can be fixed if you apply my patch, I believe.</div><div class="gmail_extra"><br><div class="gmail_quote">On Tue, Oct 25, 2016 at 12:23 PM, 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">Looks like you're right. There is no error, because DIHelper is a<br>
template and expanded in the place of usage (InputFiles.cpp) after<br>
DWARFDebugLine.h is included<br>
Once you try doing this in regular class, you'll immediately get<br>
<br>
error: invalid application of 'sizeof' to an incomplete type<br>
'llvm::DWARFDebugLine'<br>
<div class="HOEnZb"><div class="h5"><br>
2016-10-25 21:53 GMT+03:00 Rui Ueyama <<a href="mailto:ruiu@google.com">ruiu@google.com</a>>:<br>
> I actually didn't see any error when I simply converted it to unique_ptr and<br>
> removed the dtor, so I'm wondering what error you saw. In any case, doesn't<br>
> this work?<br>
><br>
> diff --git a/ELF/InputFiles.cpp b/ELF/InputFiles.cpp<br>
> index 497f946..01f8be9 100644<br>
> --- a/ELF/InputFiles.cpp<br>
> +++ b/ELF/InputFiles.cpp<br>
> @@ -43,7 +43,7 @@ template <class ELFT><br>
> DIHelper<ELFT>::DIHelper(elf::<wbr>InputFile *F) {<br>
>      return;<br>
><br>
>    DWARFContextInMemory Dwarf(*Obj.get());<br>
> -  DwarfLine = new DWARFDebugLine(&Dwarf.<wbr>getLineSection().Relocs);<br>
> +  DwarfLine.reset(new DWARFDebugLine(&Dwarf.<wbr>getLineSection().Relocs));<br>
>    DataExtractor lineData(Dwarf.getLineSection(<wbr>).Data,<br>
>                           ELFT::TargetEndianness == support::little,<br>
>                           ELFT::Is64Bits ? 8 : 4);<br>
> @@ -53,7 +53,7 @@ template <class ELFT><br>
> DIHelper<ELFT>::DIHelper(elf::<wbr>InputFile *F) {<br>
>    DwarfLine-><wbr>getOrParseLineTable(lineData, 0);<br>
>  }<br>
><br>
> -template <class ELFT> DIHelper<ELFT>::~DIHelper() { delete DwarfLine; }<br>
> +template <class ELFT> DIHelper<ELFT>::~DIHelper() {}<br>
><br>
>  template <class ELFT> std::string DIHelper<ELFT>::getLineInfo(<wbr>uintX_t<br>
> Offset) {<br>
>    DILineInfo LineInfo;<br>
> diff --git a/ELF/InputFiles.h b/ELF/InputFiles.h<br>
> index a1a63b8..6c0f5cb 100644<br>
> --- a/ELF/InputFiles.h<br>
> +++ b/ELF/InputFiles.h<br>
> @@ -58,7 +58,7 @@ public:<br>
>    std::string getLineInfo(uintX_t Offset);<br>
><br>
>  private:<br>
> -  llvm::DWARFDebugLine *DwarfLine = nullptr;<br>
> +  std::unique_ptr<llvm::<wbr>DWARFDebugLine> DwarfLine;<br>
>  };<br>
><br>
>  // The root class of input files.<br>
><br>
> On Tue, Oct 25, 2016 at 11:35 AM, Eugene Leviant <<a href="mailto:evgeny.leviant@gmail.com">evgeny.leviant@gmail.com</a>><br>
> wrote:<br>
>><br>
>> 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>
>><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<br>
>> > <<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>
>> >> ----------------<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<br>
>> >> 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<br>
>> > cpp<br>
>> > file instead of in the header so that you don't need to include the<br>
>> > DWARFContext.h, can't you?<br>
><br>
><br>
</div></div></blockquote></div><br></div>