Dependent names lookup in VC2005 B2

A

adebaene

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
 
D

Doug Harrison [MVP]

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.
 
H

Hendrik Schober

Doug Harrison said:
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

--
(e-mail address removed) 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
 

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