C ++ 11 Code :: Blocks GCC crashes when compiling a variational template of dependent member structures
I tested the variadic templating idea 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 filed 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 deploy 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 variation pattern, but I don't understand it at all. I hesitated to ask because we have to point out the exact problem, but the whole compiler said something like a dependent type.
source to share
This is an (seemingly unconfirmed) bug in GCC 4.7 (the code calls GCC 4.5 and 4.6 for ICE too, but in a different and even bolder way, namely Internal compiler error: Error reporting routines re-entered.
).
If anyone else hit this - just update to GCC 4.8 or newer where it was fixed.
source to share