template parameter type internal compiler error 
Author Message
 template parameter type internal compiler error

The following simple code

  struct foo
  {
    typedef int type;
    static const type value = 42;
  };

  template<typename T>
    struct bar
    {
      static const typename T::type value = T::value + 1;
    };

  bar<foo> test;

produces an internal compiler error with VC7 (version 13.00.9466)

Anyone encountered this one before? Is there a workaround?

-- Mat.



Sun, 10 Oct 2004 05:09:25 GMT  
 template parameter type internal compiler error
    Your code has two problems.  The first (which may be a VC++ compiler
bug) was hiding the second, which I think is an flaw in your code.

    The following works:

template<typename T>

struct bar

{

    typedef int type;

    static const type value = (T::value) + 1;

Quote:
};

    The parenthesis solve the problem of the Internal Compiler Error.
However, that merely reveals the next problem, which is that you may only
initialize integer types inside the class declaration, and the compiler has
no way of knowing if "typename T::type" is an integer type or not.

--
Truth,
James Curran
www.NJTheater.com     (Professional)
www.NovelTheory.com  (Personal)


Quote:
> The following simple code

>   struct foo
>   {
>     typedef int type;
>     static const type value = 42;
>   };

>   template<typename T>
>     struct bar
>     {
>       static const typename T::type value = T::value + 1;
>     };

>   bar<foo> test;

> produces an internal compiler error with VC7 (version 13.00.9466)

> Anyone encountered this one before? Is there a workaround?

> -- Mat.



Sun, 10 Oct 2004 06:42:57 GMT  
 template parameter type internal compiler error
On Tue, 23 Apr 2002 18:42:57 -0400, "James Curran"

Quote:



>>...
>>   struct foo
>>   {
>>     typedef int type;
>>     static const type value = 42;
>>   };

>>   template<typename T>
>>     struct bar
>>     {
>>       static const typename T::type value = T::value + 1;
>>     };

>>   bar<foo> test;
>>...
>...
>    The parenthesis solve the problem of the Internal Compiler Error.
>However, that merely reveals the next problem, which is that you may only
>initialize integer types inside the class declaration, and the compiler has
>no way of knowing if "typename T::type" is an integer type or not.

But it does know this when it instantiates the template. I thought it
was a general rule of template programming that "you only pay for what
you instantiate" - surely the template should be instantiable for any
T with integral T::type, but not for anything else.

Anyway, I've asked about this in comp.lang.c++, we'll see what
happens. :)

-- Mat.



Sun, 10 Oct 2004 07:50:52 GMT  
 template parameter type internal compiler error
On Wed, 24 Apr 2002 00:50:52 +0100, Mathew Hendry

Quote:

>On Tue, 23 Apr 2002 18:42:57 -0400, "James Curran"



>>>...
>>>   struct foo
>>>   {
>>>     typedef int type;
>>>     static const type value = 42;
>>>   };

>>>   template<typename T>
>>>     struct bar
>>>     {
>>>       static const typename T::type value = T::value + 1;
>>>     };

>>>   bar<foo> test;
>>>...
>>...
>>    The parenthesis solve the problem of the Internal Compiler Error.
>>However, that merely reveals the next problem, which is that you may only
>>initialize integer types inside the class declaration, and the compiler has
>>no way of knowing if "typename T::type" is an integer type or not.

>But it does know this when it instantiates the template. I thought it
>was a general rule of template programming that "you only pay for what
>you instantiate" - surely the template should be instantiable for any
>T with integral T::type, but not for anything else.

>Anyway, I've asked about this in comp.lang.c++, we'll see what
>happens. :)

Apparently this is a known problem with VC7, and will be fixed in the
next release.

-- Mat.



Sun, 10 Oct 2004 07:58:03 GMT  
 template parameter type internal compiler error
Here's my reply from comp.lang.c++

This is a bug in Visual C++ .NET. It will be fixed in the next release of
the compiler (as will the need for using the extra "()")

--
Jonathan Caves
Microsoft Corporation

This posting is provided "AS IS" with no warranties, and confers no rights.


Quote:
> On Tue, 23 Apr 2002 18:42:57 -0400, "James Curran"



> >>...
> >>   struct foo
> >>   {
> >>     typedef int type;
> >>     static const type value = 42;
> >>   };

> >>   template<typename T>
> >>     struct bar
> >>     {
> >>       static const typename T::type value = T::value + 1;
> >>     };

> >>   bar<foo> test;
> >>...
> >...
> >    The parenthesis solve the problem of the Internal Compiler Error.
> >However, that merely reveals the next problem, which is that you may only
> >initialize integer types inside the class declaration, and the compiler
has
> >no way of knowing if "typename T::type" is an integer type or not.

> But it does know this when it instantiates the template. I thought it
> was a general rule of template programming that "you only pay for what
> you instantiate" - surely the template should be instantiable for any
> T with integral T::type, but not for anything else.

> Anyway, I've asked about this in comp.lang.c++, we'll see what
> happens. :)

> -- Mat.



Sun, 10 Oct 2004 07:58:30 GMT  
 
 [ 5 post ] 

 Relevant Pages 

1. VC7 does NOT support template-template parameters involving non-type parameters

2. Internal compiler error in template

3. C1001 - Internal Compiler Error When Using Templates In VC++ 6.0 SP4

4. internal compiler error involving templates (cross-post)

5. Template that causes internal compiler error

6. Template problem - internal compiler error

7. FYI: VC++ 5.0 internal compiler error, probably template related

8. VC5 template induced internal compiler error

9. template and internal compiler error

10. Template invocation produces internal compiler error

11. Maybe OT: C1001 (Internal Compiler Error) when definig Templates

12. VC++6.0/SP3 Compiler Error: INTERNAL COMPILER ERROR

 

 
Powered by phpBB® Forum Software