[Bug c++/59579] New: Defaulted copy constructor of template class is instantiated even when not called (probably bug 57153)
Konstantin.Sadov at gmail dot com
gcc-bugzilla@gcc.gnu.org
Sun Dec 22 17:30:00 GMT 2013
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=59579
Bug ID: 59579
Summary: Defaulted copy constructor of template class is
instantiated even when not called (probably bug 57153)
Product: gcc
Version: 4.7.2
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: Konstantin.Sadov at gmail dot com
The following code
struct A{A()=default;A(A&)=default;};
template<typename B>struct C:B{C()=default;
#if 1
C(const C&)=default;//Fails
#else
C(const C&c):B(c){};//Works
#endif
};
C<A> d;
int main(){}
produces the following error
$g++ -std=c++11 main.cpp
main.cpp: In instantiation of 'struct C<A>':
main.cpp:9:6: required from here
main.cpp:4:1: error: 'C<B>::C(const C<B>&) [with B = A]' declared to take const
reference, but implicit declaration would take non-const
C(const C&)=default;//Fails
^
Looks like defaulted function is implicitly instantiated even if it's not used
(it's not so for user-defined functions).
GCC 4.4 worked well with this case.
More information about the Gcc-bugs
mailing list