I've run into a problem where a static template member of a template class is
not being created properly.
--- Begin Sample Code ---
#include <iostream>
using namespace std;
template <typename T>
class A
{
public:
A() { cout << "A created" << endl; }
};
template <typename T>
class AA
{
public:
AA( int i = 0 ) { cout << "AA " << i << " created" << endl; }
};
template <typename T>
class B
{
public:
static A<T> a;
static AA<T> aa;
static AA<T> aa2;
};
template <> A<char> B<char>::a;
template <> AA<char> B<char>::aa;
template <> AA<char> B<char>::aa2(1);
int main() { }
--- End Sample Code ---
When I run the above sample, I get the following:
%g++ -Wall test.cc
%./a.out
AA 1 created
%
I expected all three of class B's static template members to be constructed. It
seems that the problem occurs whether it should have called a regular default
constructor or a conversion constructor with a default parameter. The fact that
B is a template class also seems to play some role in this. I tried another
example where B was a non-template class and everything constructed properly.
--
Summary: default constructor not called for static template
member of template class
Product: gcc
Version: 3.4.1
Status: UNCONFIRMED
Severity: normal
Priority: P2
Component: c++
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: jamesp at trdlnk dot com
CC: gcc-bugs at gcc dot gnu dot org
GCC host triplet: i686-pc-linux-gnu
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=19610