[Bug c++/79555] New: Warning 'base class should be explicitly initialized in the copy constructor' issued in wrong case
reichelt at gcc dot gnu.org
gcc-bugzilla@gcc.gnu.org
Thu Feb 16 13:50:00 GMT 2017
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=79555
Bug ID: 79555
Summary: Warning 'base class should be explicitly initialized
in the copy constructor' issued in wrong case
Product: gcc
Version: 7.0
Status: UNCONFIRMED
Keywords: diagnostic
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: reichelt at gcc dot gnu.org
Target Milestone: ---
The C++ front-end (with -Wextra enabled) complains about the following code
snippet:
================================
struct A
{
A();
A(const A&);
};
struct B : virtual A
{
B(const B&) {}
// B(const B&) : A() {}
virtual int foo() = 0;
};
================================
bug.cc: In copy constructor 'B::B(const B&)':
bug.cc:9:3: warning: base class 'struct A' should be explicitly initialized in
the copy constructor [-Wextra]
B(const B&) {}
^
However, since the base class A is virtual and the class B itself is abstract,
A isn't initialized in this function anyway (and so the warning is pointless).
Even more annoying is the fact that other major compilers complain if you try
to
please GCC and initialize A (as in the comment line above):
* clang with (clang++ -Wabstract-vbase-init -c):
bug.cc:10:17: warning: initializer for virtual base class 'A' of abstract
class 'B' will never be used [-Wabstract-vbase-init]
* VisualStudio 2015 (cl -Wall)
bug.cc(10): warning C4589: Constructor of abstract class 'B' ignores
initializer for virtual base class 'A'
bug.cc(10): note: virtual base classes are only initialized by the most-derived
type
So it would be nice to suppress the warning in this specific case.
More information about the Gcc-bugs
mailing list