http://gcc.gnu.org/bugzilla/show_bug.cgi?id=49153
Summary: Compile error with template metafunctions (starting
with 4.5.x)
Product: gcc
Version: 4.6.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
AssignedTo: [email protected]
ReportedBy: [email protected]
Hi,
Starting with g++ 4.5.x this code does not compile anymore:
struct NullType;
template<typename T, typename U>
struct TypeList {
typedef T head;
typedef U tail;
};
template<typename First, template<typename, typename> class MetaFunction>
struct MetaBind1st {
template<typename Second>
struct type: MetaFunction<First, Second> {};
};
template<typename T, typename Elem>
struct AppendTypeListHelper {
typedef Elem type;
};
template<typename T>
struct AppendTypeListHelper<T, NullType> {
typedef TypeList<T, NullType> type;
};
template<typename T>
struct AppenderTypeList
{
template<typename Elem>
struct Function: MetaBind1st<T, AppendTypeListHelper>::template type<Elem>
{};
};
template<typename T>
struct Visitor;
template<typename Left, typename Right>
struct Visitor< TypeList<Left, Right> > {};
struct Test {};
template struct Visitor<AppenderTypeList<Test>::Function<NullType>::type>;
$ g++ file.cc -c -o /dev/null
file.cc:43:17: error: explicit instantiation of 'struct
Visitor<MetaBind1st<Test, AppendTypeListHelper>::type<NullType> >' before
definition of template
The error seems to be related to an issue where g++ (>=4.5.x) stops evaluating
"AppenderTypeList<Test>::Function<NullType>::type" to "TypeList<Test,
NullType>" (at least it doesn't evaluate it as such when looking for a
specialization of "Visitor" and thus it errors that it can't instantiate the
general "Visitor" that is incompletely defined).
It compiles fine with g++ < 4.5.x. Also, if I rename the nested struct "type"
from MetaBind1st to be called "Function" (and update its use from
AppenderTypeList) it compiles with g++ >= 4.5.x too.
I don't understand what the naming of that field has anything to do with the
code compiling or not.
Thanks!