[Bug c++/70551] New: member function of template instantiated even though only declaration is needed
rbock at eudoxos dot de
gcc-bugzilla@gcc.gnu.org
Tue Apr 5 16:35:00 GMT 2016
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=70551
Bug ID: 70551
Summary: member function of template instantiated even though
only declaration is needed
Product: gcc
Version: 5.3.1
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: rbock at eudoxos dot de
Target Milestone: ---
This code fails to compile:
template<typename T>
struct X
{
X(X&&) { static_assert(sizeof(T) < 1, "Intentional Failure"); }
};
auto impl() -> X<int>;
auto test() -> decltype(impl())
{
return impl();
}
int main()
{
test();
}
My understanding is that it should compile just fine. I admit, I started a
discussion on stackoverflow for this (see
http://stackoverflow.com/questions/36371571/clang-and-gcc-vs-msvc-and-icc-is-a-static-assert-in-the-copy-move-constructor-r)
Citing from the answer I deem correct:
Copy elision requires declaration of copy/move constructors but doesn't require
definition.
Member function definitions of templates are not instantiated unless their
definitions are required.
If a definition is not instantiated it cannot be tested for being ill-formed.
References:
14.7.1.1 …The implicit instantiation of a class template specialization causes
the implicit instantiation of the declarations, but not of the definitions,
default arguments, or exception-specifications of the class member functions…
14.7.1.2 Unless a member of a class template… has been explicitly instantiated
or explicitly specialized, the specialization of the member is implicitly
instantiated when the specialization is referenced in a context that requires
the member definition to exist…
More information about the Gcc-bugs
mailing list