Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / Managed C++ / March 2005

Tip: Looking for answers? Try searching our database.

ETI in VC71?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Arkadiy - 19 Mar 2005 17:13 GMT
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
Carl Daniel [VC++ MVP] - 19 Mar 2005 17:24 GMT
> Hi all,
>
[quoted text clipped - 28 lines]
>
> Can anybody comment on this?

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

-cd
Holger Grund - 19 Mar 2005 18:47 GMT
> 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
Arkadiy - 20 Mar 2005 04:59 GMT
> > 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.
[quoted text clipped - 15 lines]
> 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
Arkadiy - 20 Mar 2005 05:00 GMT
> > 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.
[quoted text clipped - 15 lines]
> 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
Arkadiy - 20 Mar 2005 05:26 GMT
> "Arkadiy" <vertleyb@hotmail.com> wrote
> Specifically, I think VC doesn't realize that
[quoted text clipped - 12 lines]
> 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
Holger Grund - 20 Mar 2005 15:36 GMT
"Arkadiy" <vertleyb@hotmail.com> wrote in message

>> Specifically, I think VC doesn't realize that
>>
[quoted text clipped - 19 lines]
> 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

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.