This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
c++0x 4.4, =default definition outside template class fails.
- From: "Simon Hill" <yacwroy at gmail dot com>
- To: gcc at gcc dot gnu dot org
- Date: Sun, 24 Aug 2008 13:41:51 +1200
- Subject: c++0x 4.4, =default definition outside template class fails.
I've just installed g++ 4.4 and I'm playing with some of the c++0x features.
The below page describes the =default and =delete syntax. (Used to
manipulate the special member functions default/copy constructor,
destructor and copy assign).
http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2007/n2346.htm
I've managed to get parts of my code working, but it seems that
defining as default a template class's special member functions
outside the class definition doesn't work.
I'm not really sure if it should, but looking at the suggested
modifications to the spec [8.4 paragraph 7] (in the above document), I
_think_ it's saying that it should work.
The problem is that the compiler fails to generate the function
(foo<int>::~foo() in the following code), which causes the linker to
report an undefined reference.
I didn't post this as a bug report as I'm not 100% sure it is a bug.
=== THIS CODE FAILS TO COMPILE ===
template <typename T>
class foo {
public:
foo() =default; // <<--- this works fine.
~foo();
};
template <typename T>
foo<T>::~foo() =default; <<--- ERROR: This doesn't get built by the compiler.
// foo<T>::~foo() {}; <<-- replacing with this line fixes the error.
int main() {
foo<int> fi;
return 0;
}
===================
=== THIS CODE COMPILES ===
class foo {
public:
foo() =default;
~foo();
};
foo::~foo() =default;
int main() {
foo fi;
return 0;
}
===================
NOTE: The reason I noticed this was that I was trying to default a
virtual destructor.
This should work, but I'm guessing that it must be done outside the
function definition, because it doesn't work inside.
However, if the above is a bug, this may also be a bug.