3

I was testing an idea with variadic templates in C++ using Code::Blocks, and when I try to compile it, the build fails and says:

'
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))

I followed the instructions and submitted a bug report, but in the meantime I want to know if I need to fix my code or get a new compiler. The code I wrote is:

#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);
}

It works if I manually expand Bar to:

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;
}

The error is somehow caused by the variadic template, but I don't understand it at all. I was hesitant to ask because we are supposed to specify the exact problem, but all the compiler said was something about a dependent type.

Praetorian
  • 106,671
  • 19
  • 240
  • 328
Bob
  • 53
  • 2
  • 3
    [Doesn't crash gcc4.9](http://coliru.stacked-crooked.com/a/cdf1359769953427), so upgrade if you can. – Praetorian Aug 28 '14 at 20:42
  • Codeblocks default binary packages mingw 4.7.1, the version which causes the error. You can also try their TDM 4.8 version, or install another version of mingw (and point codeblocks towards it.) –  Aug 28 '14 at 22:40
  • Thank you! I'll download a newer version and get Code::Blocks to use that one instead. Should someone post it as an answer, or leave this question as is? – Bob Aug 29 '14 at 02:06

1 Answers1

0

This is an (apparently unreported) bug in GCC 4.7 (the code causes GCC 4.5 and 4.6 to ICE too, but in a different and even more hilarious way, namely Internal compiler error: Error reporting routines re-entered.).

If anyone else hits this -- just upgrade to GCC 4.8 or newer, where it has been fixed.

LThode
  • 1,843
  • 1
  • 17
  • 28