[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [lmi] libstdc++ in gcc-7.3.0: std::vector<incomplete_type>
From: |
Vadim Zeitlin |
Subject: |
Re: [lmi] libstdc++ in gcc-7.3.0: std::vector<incomplete_type> |
Date: |
Tue, 24 Apr 2018 23:20:42 +0200 |
On Tue, 24 Apr 2018 20:14:10 +0000 Greg Chicares <address@hidden> wrote:
GC> On 2018-04-24 18:04, Greg Chicares wrote:
GC> > On 2018-04-24 14:26, Vadim Zeitlin wrote:
GC> [...]
GC> >> I can't help wondering why
GC> >> exactly can't this class be moved in wx_table_generator.cpp?
GC> >
GC> > I would very much like to move it there, but I tried doing exactly that,
GC> > and the compiler complained. I interpreted its complaint as meaning that
GC> > I couldn't have a std::vector<some_incomplete_type>.
But this can't be the case because the current master code already does
declare std::vector<some_incomplete_type> and yet compiles just fine:
column_info is not defined at the point of columns_ vector declaration as
of right now (commit 29e1c5ad2554733385632d87a6a2559378818f8d). So we know
that we _can_ declare std::vector<some_incomplete_type>. What we can't do
is _use_ this vector as long as the type is still incomplete -- but this
is, of course, totally expected as we really need to know at least the type
size in order to do anything with the vector of objects of this type.
GC> Specifically (note that '-std=c++17' is specified):
GC>
GC> i686-w64-mingw32-g++ -MMD -MP -MT group_quote_pdf_gen_wx.o -MF
group_quote_pdf_gen_wx.d -c -I /opt
GC> /lmi/src/lmi -I /opt/lmi/src/lmi/tools/pete-2.1.1 -I
/opt/lmi/local/lib/wx/include/i686-w64-mingw32
GC> -msw-unicode-3.1 -I /opt/lmi/local/include/wx-3.1 -I
/opt/lmi/third_party/include -I /opt/lmi/third
GC> _party/src -I /opt/lmi/local/include -I /opt/lmi/local/include/libxml2
-DLMI_WX_NEW_USE_SO -DLIBXM
GC> L_USE_DLL -DSTRICT -D_FILE_OFFSET_BITS=64 -DWXUSINGDLL -D__WXMSW__
-DBOOST_NO_AUTO_PTR -DBOOST_S
GC> TRICT_CONFIG -DBOOST_STATIC_ASSERT_HPP -std=c++17 -frounding-math
-pedantic-errors -Werror -Wall
GC> -Wcast-align -Wconversion -Wdeprecated-declarations -Wdisabled-optimization
-Wextra -Wimport -Wmult
GC> ichar -Wpacked -Wpointer-arith -Wredundant-decls -Wshadow -Wsign-compare
-Wundef -Wunreachable-code
GC> -Wwrite-strings -Wctor-dtor-privacy -Wdeprecated -Wnon-template-friend
-Woverloaded-virtual -Wpmf
GC> -conversions -Wsynth -Wcast-qual -Wno-conversion -Wno-parentheses
-D'BOOST_STATIC_ASSERT(A)=sta
GC> tic_assert((A))' -ggdb -O2 -fno-omit-frame-pointer
/opt/lmi/src/lmi/group_quote_pdf_gen_wx.cpp
GC> -ogroup_quote_pdf_gen_wx.o
GC> In file included from
/usr/lib/gcc/i686-w64-mingw32/7.3-win32/include/c++/vector:64:0,
GC> from /opt/lmi/src/lmi/ledger_evaluator.hpp:32,
GC> from /opt/lmi/src/lmi/ledger.hpp:27,
GC> from /opt/lmi/src/lmi/group_quote_pdf_gen_wx.cpp:32:
GC> /usr/lib/gcc/i686-w64-mingw32/7.3-win32/include/c++/bits/stl_vector.h: In
instantiation of 'std::ve
GC> ctor<_Tp, _Alloc>::size_type std::vector<_Tp, _Alloc>::size() const [with
_Tp = wx_table_generator:
GC> :column_info; _Alloc = std::allocator<wx_table_generator::column_info>;
std::vector<_Tp, _Alloc>::s
GC> ize_type = unsigned int]':
GC> /opt/lmi/src/lmi/wx_table_generator.hpp:100:61: required from here
GC>
/usr/lib/gcc/i686-w64-mingw32/7.3-win32/include/c++/bits/stl_vector.h:671:50:
error: invalid use of
GC> incomplete type 'class wx_table_generator::column_info'
GC> { return size_type(this->_M_impl._M_finish -
this->_M_impl._M_start); }
GC> ~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
I'm afraid this is another point against gcc. The error is correct, but
less than helpful because the compiler doesn't tell you why does it decide
to instantiate vector::size() here. Admittedly, it's not that difficult to
find it by examining the contents of wx_table_generator.hpp, but clang is
much more to the point, here is the error it gives:
In file included from
/usr/bin/../lib/gcc/x86_64-linux-gnu/8.0.1/../../../../include/c++/8.0.1/vector:64:
/usr/bin/../lib/gcc/x86_64-linux-gnu/8.0.1/../../../../include/c++/8.0.1/bits/stl_vector.h:806:50:
error: arithmetic on a pointer to an incomplete type
'wx_table_generator::column_info'
{ return size_type(this->_M_impl._M_finish -
this->_M_impl._M_start); }
~~~~~~~~~~~~~~~~~~~~~~~ ^
/home/zeitlin/src/lmi/wx_table_generator.hpp:100:56: note: in
instantiation of member function 'std::vector<wx_table_generator::column_info,
std::allocator<wx_table_generator::column_info> >::size' requested here
std::size_t columns_count() const {return columns_.size();}
^
/home/zeitlin/src/lmi/wx_table_generator.hpp:164:11: note: forward
declaration of 'wx_table_generator::column_info'
class column_info;
^
So this points immediately to the problem: we can't compile inline
columns_count() without full column_info class definition. But this is not
really a problem at all, we just need to move columns_count() out of line
and define it in wx_table_generator.cpp too.
After this there is another error left and here, to be fair, even clang
error message is not particularly clear, but it's still not difficult to
see that it's an example of the same problem as with columns_count(),
except that now it happens in an implicitly defined function, namely
wx_table_generator dtor. It is enough to declare it (but _not_ define)
explicitly in wx_table_generator.hpp and add "= default" definition to
wx_table_generator.cpp to work around this problem. And then everything
compiles just fine with both gcc and clang.
Please let me know if you'd like me to make a PR with these changes or if
you prefer to do them yourself, as you're working on this code anyhow.
Thanks,
VZ
Re: [lmi] Zebras in Git, Vadim Zeitlin, 2018/04/24