2009-09-30 179 views
0

示例代码如下:结构模板类

struct TEMP 
{ 
    int j; 
    TEMP() 
    { 
    j = 0; 
    } 
}; 

template<typename T> 
class classA 
{ 
    struct strA 
    { 
     long i; 
     strA():i(0) {} 
    }; 
    static strA obj_str; 
    classA(); 
}; 

template<typename T> 
classA<T>::classA() 
{} 

template<typename T> 
classA<TEMP>::strA classA<TEMP>::obj_str; 

int main() 
{ 
    return 0; 
} 

在编译的代码,我收到以下错误:

test1.cpp:32: internal compiler error: in import_export_decl, at cp/decl2.c:1970 Please submit a full bug report, with preprocessed source if appropriate. See http://bugzilla.redhat.com/bugzilla> for instructions. Preprocessed source stored into /tmp/ccUGE0GW.out file, please attach this to your bugreport.

我建立在x86_64的,红帽Linux的机器验证码,并且gcc版本是gcc版本4.1.2 20070626(Red Hat 4.1.2-14)

请注意此代码已经使用gcc 3.4.5版20051201(Red Hat 3.4.5-2)在i386- redhat-linux机器。

任何想法,为什么这是无法与海湾合作委员会4.1.2建立。

在此先感谢。

+0

您提交了一份完整的错误报告吗?这就是错误告诉你要做的事情。您现在可以尝试使用不同的编译器[版本]。 – strager 2009-09-30 10:42:24

+0

在这里发现了一个错误报告:http://gcc.gnu.org/bugzilla/show_bug.cgi?id=24791 - 这看起来像是一个变种。 – 2009-09-30 10:57:26

+0

内部编译器错误总是意味着编译器有问题,所以不要认为这是你的错。 – 2009-09-30 10:57:54

回答

3

在任何情况下,您的代码在下面的声明中没有多大意义。因为T参数在声明中没有用处。我认为你要么想写的下列操作之一:

// definition of static member of template 
template<typename T> 
typename classA<T>::strA classA<T>::obj_str; 

// ... or declaration of static member specialization for `T=TEMP` of template 
template<> 
classA<TEMP>::strA classA<TEMP>::obj_str; 

我怀疑这是第一个。对于编译器崩溃 - 这当然不应该在任何情况下发生:)


编辑:这个bug已经被固定在4.4.1至少 - 我认为这是没有必要了报告。

+0

对,这种错误已经报告并且已经在更高版本中修复。但是我在想,如果可以用相同的版本和一些代码更改来构建它。 是的,通过上面的代码更改,代码被编译。 谢谢:) – Ruchi 2009-09-30 11:11:48

0

我会按照错误报告。