[Bug c++/11804] Wrong warning about explicit initialization of base class default constructor
nicolas dot burrus at lrde dot epita dot fr
gcc-bugzilla@gcc.gnu.org
Wed Aug 27 15:38:00 GMT 2003
PLEASE REPLY TO gcc-bugzilla@gcc.gnu.org ONLY, *NOT* gcc-bugs@gcc.gnu.org.
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=11804
------- Additional Comments From nicolas dot burrus at lrde dot epita dot fr 2003-08-27 15:38 -------
Sorry, I wasn't clear. The problem is that B and C are empty classes and only
have default copy contructors (otherwise it could be fine to warn even if B
and C are empty).
I'm not familiar with gcc internals, but here is an extract of the source, in
gcc/cp/init.c line 659 (on mainline):
if (extra_warnings && !arguments
&& DECL_COPY_CONSTRUCTOR_P (current_function_decl)
&& TYPE_NEEDS_CONSTRUCTING (BINFO_TYPE (subobject))
&& TYPE_HAS_CONSTRUCTOR (BINFO_TYPE (subobject)))
warning ("base class `%#T' should be explicitly initialized in the "
"copy constructor",
BINFO_TYPE (subobject));
I think the problem comes from TYPE_NEEDS_CONSTRUCTING, which can be true even
if the class is empty if there is virtual inheritance or virtual functions
into it. The second case seems to corresponds to PR c++/5645.
I think the warning should be conditioned by a a predicate like
CLASSTYPE_NEARLY_EMPTY_P(). I don't reopen the bug myself since I may be wrong
though.
More information about the Gcc-bugs
mailing list