[Bug c++/49153] New: Compile error with template metafunctions (starting with 4.5.x)

2011-05-24 Thread dizzy at roedu dot net
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: unassig...@gcc.gnu.org
ReportedBy: di...@roedu.net


Hi,

Starting with g++ 4.5.x this code does not compile anymore:
struct NullType;

template
struct TypeList {
  typedef T head;
  typedef U tail;
};

template class MetaFunction>
struct MetaBind1st {
  template
  struct type: MetaFunction {};
};


template
struct AppendTypeListHelper {
  typedef Elem type;
};

template
struct AppendTypeListHelper {
  typedef TypeList type;
};

template
struct AppenderTypeList
{
  template
  struct Function: MetaBind1st::template type
{};
};


template
struct Visitor;

template
struct Visitor< TypeList > {};


struct Test {};

template struct Visitor::Function::type>;

$ g++ file.cc -c -o /dev/null
file.cc:43:17: error: explicit instantiation of 'struct
Visitor::type >' before
definition of template

The error seems to be related to an issue where g++ (>=4.5.x) stops evaluating
"AppenderTypeList::Function::type" to "TypeList" (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!


[Bug c++/49153] Compile error with template metafunctions (starting with 4.5.x)

2011-05-24 Thread dizzy at roedu dot net
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=49153

dizzy at roedu dot net changed:

   What|Removed |Added

 Status|UNCONFIRMED |RESOLVED
 Resolution||INVALID

--- Comment #2 from dizzy at roedu dot net 2011-05-25 00:47:53 UTC ---
I see. I did test Comeau online and it wasn't failing but now it does, I
probably used the fixed code with it or something.

Anyways, since it fails with other compilers it's very likely something to do
with the code as you said so I'm changing the status to resolved/invalid until
I come back with further relevant information. Thanks!


[Bug c++/49153] Compile error with template metafunctions (starting with 4.5.x)

2011-05-25 Thread dizzy at roedu dot net
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=49153

--- Comment #3 from dizzy at roedu dot net 2011-05-25 16:53:52 UTC ---
Indeed it seems a problem with the code because of the semantics of the
injected class names. 

Namely that a nested (in MetaBind1st) struct "type" is defined which
incidentally inherits a nested typedef "type". The injected class name of the
struct ("type") will hide the inherited nested typedef ("type") and thus when
trying to locate it with "AppenderTypeList::Function::type" it
will find the injected class name of the "type" struct instead of the nested
inherited typedef.

Sorry for the spam.