2012年3月20日火曜日

Variadic Templates わからない

Variadic Template 始めましたに続き、連投です。

Variadic Template Templates を書いていたら、内部コンパイルエラーになってしまいました。
コンパイラは gcc version 4.7.0 20120128 (experimental) (GCC) です。
そもそも、書いたコードが規格に沿っていないのかもしれませんが。。。

まずは、こちらの Variadic Templates のコード
struct TypeList0 {};

template<typename T, typename ...Args>
struct VariadicTypeList
{
    typedef T   Head;
    typedef VariadicTypeList<Args...>   Tail;
};
template<typename T>
struct VariadicTypeList<T>
{
    typedef T   Head;
    typedef TypeList0   Tail;
};

template<typename ...Args>
struct Types
{
    typedef VariadicTypeList<Args...>   type;
};

int main(void)
{
    VariadicTypeList<int, float>::Head c;
    Types<int, float>::type::Head d;
    return 0;
}
http://ideone.com/23bQ6
こちらは、問題なくコンパイルできます。

つづいて、問題の Variadic Template Templates のコード
struct TemplateTypeList0 {};

template<template<typename> class U>
struct TemplateTypeSel
{
    template<typename T>
    struct bind
    {
        typedef U<T>    type;
    };
};

template<template<typename T> class T1, template<typename T> class ...Args>
struct VariadicTemplateTypeList
{
    typedef TemplateTypeSel<T1> Head;
    typedef VariadicTemplateTypeList<Args...>   Tail;
};
template<template<typename T> class T1>
struct VariadicTemplateTypeList<T1>
{
    typedef TemplateTypeSel<T1> Head;
    typedef TemplateTypeList0   Tail;
};

template<template<typename T> class ...Args>
struct Templates
{
    typedef VariadicTemplateTypeList<Args...> type;
};

template<typename T>
struct Y
{
    T v;
};

int main(void)
{
    VariadicTemplateTypeList<Y, Y>::Head::bind<int>::type a;
    Templates<Y>::type::Head::bind<int>::type b;
    return 0;
}
http://ideone.com/q5lgt
このコードがコンパイルできないんですよね。。。

$ g++ -std=c++11 test1.cpp
test1.cpp: In instantiation of 'struct VariadicTemplateTypeList<Y, Y>':
test1.cpp:43:32:   required from here
test1.cpp:13:71: internal compiler error: Segmentation fault
Please submit a full bug report,
with preprocessed source if appropriate.
See  for instructions.

これってバグ報告した方がいいんでしょうかね?
やりたいことは、最新の iutest で、
-DIUTEST_HAS_VARIADIC_TEMPLATE_TEMPLATES=1 としていただければわかると思います。

なんでも良いので、なにかあればジャンジャン指摘してください。お願いします。

追記
gcc 4.7.0 がリリースされたので、こちら(Fortran, C and C++ for Windows)のものを使用して試してみたました。が、ダメでした。

0 件のコメント:

コメントを投稿