2014-02-11 19 views
0
//class we're trying to generate 
template <int a, foo b> 
class A 
{ 
public: 
    A() 
    { 
    std::cout << a << "," << (int)b << std::endl; 

    } 
}; 

//class which generates information 
template <typename T> 
struct B 
{ 
    typedef T value_type; 
    static const T val; 
}; 

template <typename... B> 
struct madscience_intitializer 
{ 
    template <typename B::value_type... args> 
    using ret_type = A<args...>; 
}; 

int main() 
{ 
    madscience_intitializer<B<int>,B<foo> >::ret_type<1,foo::y> a; 
} 

打在G ++,我得到G ++錯誤,而與可變參數模板

/home/njclimer/source/testdir/main/main2.cpp: In function 'int main()': 
/home/njclimer/source/testdir/main/main2.cpp:38:61: internal compiler error: in dependent_type_p, at cp/pt.c:19526 
madscience_intitializer<B<int>,B<foo> >::ret_type<1,foo::y> a; 


Please submit a full bug report, 
with preprocessed source if appropriate. 
See <http://bugzilla.redhat.com/bugzilla> for instructions. 
Preprocessed source stored into /tmp/ccAhk6TK.out file, please attach this to your bugreport. 

有其他人碰到這個?這是編譯器的實際錯誤還是它是我的代碼中的錯誤?

我跑

g++ (GCC) 4.8.2 20131212 (Red Hat 4.8.2-7) 
                 ^

隨着國旗-std = GNU ++ 0x中-02 -g

+6

只要編譯器說「內部錯誤」,那麼它就是一個值得報告的bug。 –

+0

@PeterM足夠公平,打開了一個錯誤報告。 – IdeaHat

回答

-1

顯然編譯器不應該崩潰,但您的代碼將無法編譯反正我覺得。

不能傳遞非整數類型作爲模板的參數,並且該:

模板 使用ret_type = A;

應該是

使用ret_type = A;

+0

1)'template void bar(){std :: cout <<(int)f << std :: endl;}',枚舉是整型。 2)使用語句的模板很好。 – IdeaHat