【问题标题】:C++11 Code::Blocks GCC crashes when compiling variadic template of dependent member structsC++11 Code::Blocks 编译依赖成员结构的可变参数模板时 GCC 崩溃
【发布时间】:2014-10-22 19:59:34
【问题描述】:

我正在使用 Code::Blocks 在 C++ 中使用可变参数模板测试一个想法,当我尝试编译它时,构建失败并显示:

'
in dependent_type_p, at cp/pt.c:19367
Please submit a full bug report,
with preprocessed source if appropriate.
See <http://tdm-gcc.tdragon.net/bugs> for instructions.
Process terminated with status 1 (0 minute(s), 1 second(s))
0 error(s), 0 warning(s) (0 minute(s), 1 second(s))

我按照说明提交了错误报告,但同时我想知道是否需要修复我的代码或获取新的编译器。我写的代码是:

#include <iostream>
#include <array>
using namespace std;

struct Foo1
{
    struct init {};
};

struct Foo2 : public Foo1
{
    struct init{};
};

struct Foo3 : public Foo2
{
    struct init{};
};

template <typename... Args>
void Bar(typename Args::init... args)
{
    array<void*, sizeof...(Args) + 2> t = {nullptr, &args..., nullptr};
    for (size_t x = 1; x < sizeof...(Args) + 1; ++x)
        cout << t[x] << endl;
}

int main()
{
    Foo1::init a;
    Foo2::init b;
    Foo3::init c;
    Bar<Foo1, Foo2, Foo3>(a, b, c);
}

如果我手动将Bar 扩展为:

template <typename A, typename B, typename C>
void Bar(typename A::init a, typename B::init b, typename C::init c)
{
    array<void*, 5> t = {nullptr, &a, &b, &c, nullptr};
    for (size_t x = 1; x < 4; ++x)
        cout << t[x] << endl;
}

错误是由可变参数模板引起的,但我完全不明白。我犹豫了一下,因为我们应该指定确切的问题,但编译器所说的只是依赖类型。

【问题讨论】:

  • Doesn't crash gcc4.9,如果可以,请升级。
  • Codeblocks 默认二进制包 mingw 4.7.1,导致错误的版本。您也可以尝试他们的 TDM 4.8 版本,或安装另一个版本的 mingw(并将代码块指向它。)
  • 谢谢!我将下载一个较新的版本并获取 Code::Blocks 来使用该版本。应该有人将其发布为答案,还是保留这个问题?

标签: c++ gcc c++11 variadic-templates internal-compiler-error


【解决方案1】:

这是 GCC 4.7 中的一个(显然未报告的)错误(该代码也会导致 GCC 4.5 和 4.6 进入 ICE,但以不同且更有趣的方式,即 Internal compiler error: Error reporting routines re-entered.)。

如果其他人遇到此问题 - 只需升级到已修复的 GCC 4.8 或更高版本。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-11-23
    • 2013-03-30
    • 1970-01-01
    • 2010-09-05
    • 1970-01-01
    • 2011-11-03
    • 1970-01-01
    相关资源
    最近更新 更多