This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c++/63267] New: Static member of template class is not constructed before it's used.
- From: "yuxiao1985 at hotmail dot com" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Mon, 15 Sep 2014 08:07:31 +0000
- Subject: [Bug c++/63267] New: Static member of template class is not constructed before it's used.
- Auto-submitted: auto-generated
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=63267
Bug ID: 63267
Summary: Static member of template class is not constructed
before it's used.
Product: gcc
Version: 4.4.7
Status: UNCONFIRMED
Severity: major
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: yuxiao1985 at hotmail dot com
// test.cpp
#include <iostream>
using namespace std;
struct Output
{
Output();
void doIt() { cout<<"do it a:"<<a<<"\n";}
int a;
};
Output::Output(): a(100)
{
cout<<"Output constructed\n";
}
template <class T>
class Test
{
public:
static void use(const Output& ) { }
static int callStaticMember();
static Output out;
};
template <class T>
Output Test<T>::out;
template <class T>
int Test<T>::callStaticMember()
{
use(out);
out.doIt();
return 0;
}
int a = Test<int>::callStaticMember();
int main()
{
return 0;
}
The result is not correct. the static member should be constructed first.
----------------------------
[yxiao2@centos:~]$ g++ test.cpp
[yxiao2@centos:~]$ ./a.out
do it a:0
Output constructed