簡體   English   中英

使用可變參數模板時出現G ++錯誤

[英]G++ error while playing with variadic templates

//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 ++中,我得到

/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 -O2 -g

顯然,編譯器不應該崩潰,但是我認為您的代碼也不會編譯。

您不能將非整數類型作為模板參數傳遞,這是:

使用ret_type = A的模板;

應該

使用ret_type = A;

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM