serge1 / ELFIO

ELFIO - ELF (Executable and Linkable Format) reader and producer implemented as a header only C++ library
http://serge1.github.io/ELFIO
MIT License
726 stars 157 forks source link

Cannot compile ELFIO with "-Wall -Werror -Wextra" #120

Closed covanam closed 1 year ago

covanam commented 1 year ago

I turned on extra GCC warnings today, and my project can no longer be compiled because of these GCC warnings:

g++ -g -IELFIO -lcapstone -lkeystone -Wall -Werror -Wextra -c -o test.o test.cpp In file included from ELFIO/elfio/elfio.hpp:40, from disasm.h:4, from test.cpp:1: ELFIO/elfio/elfio_section.hpp: In instantiation of ‘bool ELFIO::section_impl::load(std::istream&, std::streampos, bool) [with T = ELFIO::Elf32_Shdr; std::istream = std::basic_istream; std::streampos = std::fpos<__mbstate_t>]’: ELFIO/elfio/elfio_section.hpp:233:10: required from here ELFIO/elfio/elfio_section.hpp:239:17: error: missing initializer for member ‘ELFIO::Elf32_Shdr::sh_type’ [-Werror=missing-field-initializers] 239 | header = { 0 }; | ~~^~~~~ ELFIO/elfio/elfio_section.hpp:239:17: error: missing initializer for member ‘ELFIO::Elf32_Shdr::sh_flags’ [-Werror=missing-field-initializers] ELFIO/elfio/elfio_section.hpp:239:17: error: missing initializer for member ‘ELFIO::Elf32_Shdr::sh_addr’ [-Werror=missing-field-initializers]

(I cut out some warnings to keep this short)

Although honestly I think GCC is being a bit stupid here. Nonetheless this means ELFIO cannot be compiled with GCC with "-Wall -Werror -Wextra". It doesn't take much work to fix this anyway, so I think we should.

I propose removing the header = { 0 };, it doesn't seem necessary anyways. Another solution is using memset to zero initialize. Both options suppress the warnings for me.

I will leave it to you to decide what to do.

Thanks for the awesome library!

serge1 commented 1 year ago

Addressed in PR #121