ETI in VC71?

A

Arkadiy

Hi all,

I was under impression that the ETI bug was completely fixed in VC71.
However, recently I ran into a problem that makes me think otherwise.
The following minimal example demonstrates the problem that looks very
similar to ETI:

------------------------------
template<int n> struct Y
{
typedef void type;
};

template<> struct Y<4>
{};

template<class T>
T foo();

template <class T>
struct X
{
typedef typename Y<sizeof(foo<T>())>::type type;
};

int main()
{
return 0;
}
---------------------------------

Can anybody comment on this?

Thanks in advance and best regards,
Arkadiy
 
C

Carl Daniel [VC++ MVP]

Arkadiy said:
Hi all,

I was under impression that the ETI bug was completely fixed in VC71.
However, recently I ran into a problem that makes me think otherwise.
The following minimal example demonstrates the problem that looks very
similar to ETI:

------------------------------
template<int n> struct Y
{
typedef void type;
};

template<> struct Y<4>
{};

template<class T>
T foo();

template <class T>
struct X
{
typedef typename Y<sizeof(foo<T>())>::type type;
};

int main()
{
return 0;
}

AFIAK there were no significant changes in the way VC handles template
instantiation in VC7.1 (or VC8).

-cd
 
H

Holger Grund

Arkadiy said:
I was under impression that the ETI bug was completely fixed in VC71.
However, recently I ran into a problem that makes me think otherwise.
The following minimal example demonstrates the problem that looks very
similar to ETI:
I think this a bit different from the nightmare in previous VC versions.

[..]
Specifically, I think VC doesn't realize that
template <class T>
struct X
{
typedef typename Y<sizeof(foo<T>())>::type type;

is a dependent name. I can't access my VC 7.1 installation right
now, but you could try to drop the typename and IIRC the
compiler won't complain. Or try to add a "+ 0 * sizeof(T)"
to make sure the compiler thinks it's a dependent name.

So the compiler see typedef Y<4>::type type;
in which case it's okay to instantiate Y<4>::type even if
X<T>::type is not instantiated.

So I think it's not exactly ETI. Nonetheless it's annoying
enough.

-hg
 
A

Arkadiy

Holger said:
Arkadiy said:
I was under impression that the ETI bug was completely fixed in VC71.
However, recently I ran into a problem that makes me think otherwise.
The following minimal example demonstrates the problem that looks very
similar to ETI:
I think this a bit different from the nightmare in previous VC versions.

[..]
Specifically, I think VC doesn't realize that
template <class T>
struct X
{
typedef typename Y<sizeof(foo<T>())>::type type;

is a dependent name. I can't access my VC 7.1 installation right
now, but you could try to drop the typename and IIRC the
compiler won't complain. Or try to add a "+ 0 * sizeof(T)"
to make sure the compiler thinks it's a dependent name.

Second one helps. Now I have to figure out whether it solves my
original problem or my minimal example was wrong.
So the compiler see typedef Y<4>::type type;
in which case it's okay to instantiate Y<4>::type even if
X<T>::type is not instantiated.

So I think it's not exactly ETI. Nonetheless it's annoying
enough.

Thanks a lot.
Arkadiy
 
A

Arkadiy

Holger said:
Arkadiy said:
I was under impression that the ETI bug was completely fixed in VC71.
However, recently I ran into a problem that makes me think otherwise.
The following minimal example demonstrates the problem that looks very
similar to ETI:
I think this a bit different from the nightmare in previous VC versions.

[..]
Specifically, I think VC doesn't realize that
template <class T>
struct X
{
typedef typename Y<sizeof(foo<T>())>::type type;

is a dependent name. I can't access my VC 7.1 installation right
now, but you could try to drop the typename and IIRC the
compiler won't complain. Or try to add a "+ 0 * sizeof(T)"
to make sure the compiler thinks it's a dependent name.

Second one helps. Now I have to figure out whether it solves my
original problem or my minimal example was wrong.
So the compiler see typedef Y<4>::type type;
in which case it's okay to instantiate Y<4>::type even if
X<T>::type is not instantiated.

So I think it's not exactly ETI. Nonetheless it's annoying
enough.

Thanks a lot.
Arkadiy
 
A

Arkadiy

Holger said:
is a dependent name. I can't access my VC 7.1 installation right
now, but you could try to drop the typename and IIRC the
compiler won't complain. Or try to add a "+ 0 * sizeof(T)"
to make sure the compiler thinks it's a dependent name.

So the compiler see typedef Y<4>::type type;
in which case it's okay to instantiate Y<4>::type even if
X<T>::type is not instantiated.

As I mentioned before, adding "+ 0 * sizeof(T)" makes the code compile.
However, if you take my original code and just replace 4 with any
other number, it also compiles. If this was a problem of the compiler
not recognizing a dependent name, the exact number used in the
specialization wouldn't matter, would it? But, since 4 is exactly
sizeof(int), this makes me to believe that the compiler tries to
temporaruly replace "T" with integer, as in ETI.

Regards,
Arkadiy
 
H

Holger Grund

Arkadiy said:
As I mentioned before, adding "+ 0 * sizeof(T)" makes the code compile.
However, if you take my original code and just replace 4 with any
other number, it also compiles. If this was a problem of the compiler
not recognizing a dependent name, the exact number used in the
specialization wouldn't matter, would it? But, since 4 is exactly
sizeof(int), this makes me to believe that the compiler tries to
temporaruly replace "T" with integer, as in ETI.
That depends on how you put it ;-) If you consider
Y<sizeof(foo<T>())>::type a non-dependent name it should
be interpreted. But, oc, T is not known at this point in time
and probably substituted by an int.

It's IMHO a bit different from the VC 6 ETI issues where
it seemed that the compiler instantiated templates during
parsing. Oc, both things might be symptoms of the same
issue.

BTW: The code compiles fine with VC 8 beta.

-hg
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top