[PATCH] D76499: [obj2yaml] - Simplify and reduce `ELFDumper<ELFT>::dumpSections`. NFCI.

Fangrui Song via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Mar 20 15:12:42 PDT 2020


MaskRay accepted this revision.
MaskRay added inline comments.
This revision is now accepted and ready to land.


================
Comment at: llvm/tools/obj2yaml/elf2yaml.cpp:251
+  auto GetDumper = [&, this](unsigned Type)
+      -> std::function<Expected<ELFYAML::Chunk *>(const Elf_Shdr *)> {
+    switch (Type) {
----------------
grimar wrote:
> MaskRay wrote:
> > std::function<...> is not needed. How about returning a pointer to class member function?
> > 
> > 
> I wanted, but I do not think we can. The following will not compile:
> 
> ```
> typedef Expected<ELFYAML::Chunk *> (ELFDumper<ELFT>::*Fn)(const Elf_Shdr *);
> auto GetDumper = [this](unsigned Type) -> Fn {
> switch (Type) {
>   case ELF::SHT_DYNAMIC:
>     return &ELFDumper<ELFT>::dumpDynamicSection;
> ...
>   default:
>     return nullptr;
>   }
> };
> ```
> 
> Because, for example, `dumpDynamicSection` returns `Expected<ELFYAML::DynamicSection*>` and not `Expected<ELFYAML::Chunk *>`. Other dumpers follows.
> 
> It seems can be fixed by changing return type of all dumper methods to ``Expected<ELFYAML::Chunk *>``,
> but I am not sure it worth doing. `std::function` fits better here I think.
I see. C++ can't infer that the return type of a function type is covariant :(


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D76499/new/

https://reviews.llvm.org/D76499





More information about the llvm-commits mailing list