Template problem

Tech-Archive recommends: Fix windows errors by optimizing your registry



The following code generates errors when compiled using VC++ 7.1. However,
gcc 3.2.2 and comeau online have no problems with it. Is this illegal code
or a compiler bug? If it is the latter; was it fixed in the latest release
of VC++? Are there any workarounds for my version?

Thank you in advance!

====================
template <typename T>
struct Outer
{
template <T value = 0>
struct Inner {};
};

int main ()
{
Outer<int>::Inner<> fail;
}
====================
cl test.cpp
Microsoft (R) 32-bit C/C++ Optimizing Compiler Version 13.10.3077 for 80x86
Copyright (C) Microsoft Corporation 1984-2002. All rights reserved.

test.cpp
test.cpp(10) : error C2976: 'Outer<T>::Inner' : too few template arguments
with
[
T=int
]
test.cpp(5) : see declaration of 'Outer<T>::Inner'
with
[
T=int
]
test.cpp(10) : error C2955: 'Outer<T>::Inner' : use of class template
requires t
emplate argument list
with
[
T=int
]
test.cpp(5) : see declaration of 'Outer<T>::Inner'
with
[
T=int
]
test.cpp(10) : error C2955: 'Outer<T>::Inner' : use of class template
requires t
emplate argument list
with
[
T=int
]
test.cpp(5) : see declaration of 'Outer<T>::Inner'
with
[
T=int
]
test.cpp(10) : error C2133: 'fail' : unknown size
test.cpp(10) : error C2512: 'Outer<T>::Inner' : no appropriate default
construct
or available
with
[
T=int
]
test.cpp(10) : error C2262: 'fail' : cannot be destroyed


.



Relevant Pages

  • Template Problem
    ... Is this illegal code ... or a compiler bug? ... emplate argument list ...
    (microsoft.public.dotnet.languages.vc)
  • Re: MR&C 7.9
    ... using illegal code, ... compilers, or perhaps even on the same compiler with different options. ... In some cases it will be set to zero as you observed. ... because you observe some behavior in one case, ...
    (comp.lang.fortran)
  • Re: Do loops until HUGE?
    ... But the compiler is also free to do a lot of other things, ... some of which involve exceeding limits and thus making the program ... And regardless of how the trip count is computed, ... things a compiler may do with such illegal code, ...
    (comp.lang.fortran)
  • Re: Specialisation of a template that results to another template
    ... > Is it illegal code or is it a limitation of the MS compiler? ... VC7.0 does not support partial specialisations. ...
    (comp.lang.cpp)