Re: C++ conversion status update
Simon Marchi <[email protected]>
| Newsgroups | gmane.comp.gdb.devel |
|---|---|
| Message-ID | <CAFXXi0mju2QKzp40emJWqxkRrhWMLK77nBOLty-ub+5oGKaH3A@mail.gmail.com> |
On 15 December 2015 at 06:46, Jose E. Marchesi <[email protected]> wrote: > g++ -g -O2 -I. -I../../gdb -I../../gdb/common -I../../gdb/config -DLOCALEDIR="\"/usr/local/share/locale\"" -DHAVE_CONFIG_H -I../../gdb/../include/opcode -I../../gdb/../opcodes/.. -I../../gdb/../readline/.. -I../../gdb/../zlib -I../bfd -I../../gdb/../bfd -I../../gdb/../include -I../libdecnumber -I../../gdb/../libdecnumber -I../../gdb/gnulib/import -Ibuild-gnulib/import -DTUI=1 -I/usr/include/python2.6 -I/usr/include/python2.6 -Wall -Wpointer-arith -Wno-unused -Wunused-value -Wunused-function -Wno-switch -Wno-char-subscripts -Wempty-body -Wno-sign-compare -Wno-write-strings -Wno-narrowing -Wformat-nonliteral -Werror -c -o sparc64-tdep.o -MT sparc64-tdep.o -MMD -MP -MF .deps/sparc64-tdep.Tpo ../../gdb/sparc64-tdep.c > cc1plus: warnings being treated as errors > In file included from ../../gdb/target.h:74, > from ../../gdb/exec.h:23, > from ../../gdb/gdbcore.h:29, > from ../../gdb/sparc64-tdep.c:27: > ../../gdb/btrace.h: In function ‘size_t VEC_btrace_insn_s_embedded_size(int)’: > ../../gdb/btrace.h:84: error: invalid access to non-static data member ‘VEC_btrace_insn_s::vec’ of NULL object > ../../gdb/btrace.h:84: error: (perhaps the ‘offsetof’ macro was used incorrectly) > ../../gdb/btrace.h: In function ‘VEC_btrace_insn_s* VEC_btrace_insn_s_alloc(int)’: > ../../gdb/btrace.h:84: error: invalid access to non-static data member ‘VEC_btrace_insn_s::vec’ of NULL object > ../../gdb/btrace.h:84: error: (perhaps the ‘offsetof’ macro was used incorrectly) > ../../gdb/btrace.h: In function ‘VEC_btrace_insn_s* VEC_btrace_insn_s_copy(VEC_btrace_insn_s*)’: > ../../gdb/btrace.h:84: error: invalid access to non-static data member ‘VEC_btrace_insn_s::vec’ of NULL object > ../../gdb/btrace.h:84: error: (perhaps the ‘offsetof’ macro was used incorrectly) > ../../gdb/btrace.h: In function ‘VEC_btrace_insn_s* VEC_btrace_insn_s_merge(VEC_btrace_insn_s*, VEC_btrace_insn_s*)’: > ../../gdb/btrace.h:84: error: invalid access to non-static data member ‘VEC_btrace_insn_s::vec’ of NULL object > ../../gdb/btrace.h:84: error: (perhaps the ‘offsetof’ macro was used incorrectly) > ../../gdb/btrace.h: In function ‘int VEC_btrace_insn_s_reserve(VEC_btrace_insn_s**, int, const char*, unsigned int)’: > ../../gdb/btrace.h:84: error: invalid access to non-static data member ‘VEC_btrace_insn_s::vec’ of NULL object > ../../gdb/btrace.h:84: error: (perhaps the ‘offsetof’ macro was used incorrectly) > At global scope: > cc1plus: error: unrecognized command line option "-Wno-narrowing" > make[2]: *** [sparc64-tdep.o] Error 1 > make[2]: Leaving directory `/home/jemarch/couts2/binutils-gdb/build/gdb' > make[1]: *** [all-gdb] Error 2 > make[1]: Leaving directory `/home/jemarch/couts2/binutils-gdb/build' > make: *** [all] Error 2 This can be reproduced with g++ 4.4 on any architecture, i think. This seems to be caused by the interaction of enum_flags and the vector implementation. After preprocessing we have this: __builtin_offsetof (VEC_btrace_insn_s, vec) However, VEC_btrace_insn_s is a non-POD data type, because it ultimately contains an enum_flags object, which is non-POD. VEC_btrace_insn_s btrace_insn_s vec[1]; btrace_insn_flags flags; (enum_flags <enum btrace_insn_flag>) From what I read, using offsetof on a non-POD structure is an undefined behavior, at least in C++98. I don't know if it has changed in later standard versions, but later g++ do not complain. For g++ 4.4, it is possible to silence the warning/error with -Wno-invalid-offsetof, if we know that it still produces good results.