By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,364 Members | 1,651 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,364 IT Pros & Developers. It's quick & easy.

Dependent names lookup in VC2005 B2

P: n/a
Hello all,

I just checked that the following did compile with VC2005 b2, and I
think it shouldn't:

template <typename T> struct A
{
typedef int Foo;
};

template <typename T> class B : public A<T>
{
Foo i; //line 1
};
int main()
{
B<float> b;
}

I believe that Foo is a dependent-name in B context, and therefore line
1 should be "typename A<T>::Foo i;".

Comeau online and gcc seems to agree with my reasoning, but I am quite
unable to fully understand norm 14.6.2. Could anyone shed some light on
this? Is this code legal or not?

Arnaud
MVP - VC

Nov 17 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
On 16 Jun 2005 01:09:52 -0700, ad******@club-internet.fr wrote:
Hello all,

I just checked that the following did compile with VC2005 b2, and I
think it shouldn't:

template <typename T> struct A
{
typedef int Foo;
};

template <typename T> class B : public A<T>
{
Foo i; //line 1
};
int main()
{
B<float> b;
}

I believe that Foo is a dependent-name in B context, and therefore line
1 should be "typename A<T>::Foo i;".

Comeau online and gcc seems to agree with my reasoning, but I am quite
unable to fully understand norm 14.6.2. Could anyone shed some light on
this? Is this code legal or not?


No, the code above isn't legal. If you remove A<T> as a base class and
refer to Foo with A<T>::Foo, I expect you'll get an error. If instead you
add "int Foo;" as a global in front of B's defintion, I expect you won't
get an error. The problem is that VC still doesn't correctly implement the
"two-phase" lookup rule and is still quite lax about looking into template
bases.

--
Doug Harrison
Microsoft MVP - Visual C++
Nov 17 '05 #2

P: n/a
Doug Harrison [MVP] <ds*@mvps.org> wrote:
On 16 Jun 2005 01:09:52 -0700, ad******@club-internet.fr wrote:
Hello all,

I just checked that the following did compile with VC2005 b2, and I
think it shouldn't:

template <typename T> struct A
{
typedef int Foo;
};

template <typename T> class B : public A<T>
{
Foo i; //line 1
};
int main()
{
B<float> b;
}

I believe that Foo is a dependent-name in B context, and therefore line
1 should be "typename A<T>::Foo i;".

Comeau online and gcc seems to agree with my reasoning, but I am quite
unable to fully understand norm 14.6.2. Could anyone shed some light on
this? Is this code legal or not?


No, the code above isn't legal. [...]


I think it is indeed illegal. Comeau agrees.
<lazy_mode>I'm sure CW agrees, too. At least
it keeps finding such errors that VC let's
me get away with.</lazy_mode>

Schobi

--
Sp******@gmx.de is never read
I'm Schobi at suespammers dot org

"Coming back to where you started is not the same as never leaving"
Terry Pratchett
Nov 17 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.