Bug in VC++ 2003 (base class name lookup issue?) 
Author Message
 Bug in VC++ 2003 (base class name lookup issue?)

I'm getting an error compiling the following code, although I believe
it is legal (and it is accepted by VC++ 2002 and by Comeau):

template <typename T> struct Template
{
   void f();

Quote:
};

struct Outer
{
   typedef Template<int> Base;

   struct X : Base
   {
      void g() { Base::f(); } // Error here
   };

Quote:
};

When compiled with "cl -c abc.cpp" I get:

Microsoft (R) 32-bit C/C++ Optimizing Compiler Version 13.10.3077 for
80x86
Copyright (C) Microsoft Corporation 1984-2002. All rights reserved.

abc.cpp
abc.cpp(12) : error C2352: 'Template<T>::f' : illegal call of
non-static member
function
        with
        [
            T=int
        ]
        abc.cpp(3) : see declaration of 'Template<T>::f'
        with
        [
            T=int
        ]

But it's legal to call a non-static member function if it's defined in
a base class (see 9.3.1 in the standard), and Base (aka Template<int>)
is a base class of X.

- Alan



Tue, 06 Dec 2005 17:08:06 GMT  
 Bug in VC++ 2003 (base class name lookup issue?)
I don't know if this code is standard. However, if you
place "typedef Template<int> Base;" Before "struct Outer
{...};", it works okay. Or, if you use "__super::f()", it
works okay. Thus, the compiler is having problems with the
typedef inside the scope of X::g()!

Quote:
>-----Original Message-----
>I'm getting an error compiling the following code,
although I believe
>it is legal (and it is accepted by VC++ 2002 and by
Comeau):

>template <typename T> struct Template
>{
>   void f();
>};

>struct Outer
>{
>   typedef Template<int> Base;

>   struct X : Base
>   {
>      void g() { Base::f(); } // Error here
>   };
>};

>When compiled with "cl -c abc.cpp" I get:

>Microsoft (R) 32-bit C/C++ Optimizing Compiler Version
13.10.3077 for
>80x86
>Copyright (C) Microsoft Corporation 1984-2002. All rights
reserved.

>abc.cpp
>abc.cpp(12) : error C2352: 'Template<T>::f' : illegal
call of
>non-static member
>function
>        with
>        [
>            T=int
>        ]
>        abc.cpp(3) : see declaration of 'Template<T>::f'
>        with
>        [
>            T=int
>        ]

>But it's legal to call a non-static member function if
it's defined in
>a base class (see 9.3.1 in the standard), and Base (aka
Template<int>)
>is a base class of X.

>- Alan
>.



Tue, 06 Dec 2005 19:35:54 GMT  
 Bug in VC++ 2003 (base class name lookup issue?)
Also, you code works as is when change the following:
    Base::f();
to:
    Outer::Base::f();

Quote:
>-----Original Message-----
>I'm getting an error compiling the following code,
although I believe
>it is legal (and it is accepted by VC++ 2002 and by
Comeau):

>template <typename T> struct Template
>{
>   void f();
>};

>struct Outer
>{
>   typedef Template<int> Base;

>   struct X : Base
>   {
>      void g() { Base::f(); } // Error here
>   };
>};

>When compiled with "cl -c abc.cpp" I get:

>Microsoft (R) 32-bit C/C++ Optimizing Compiler Version
13.10.3077 for
>80x86
>Copyright (C) Microsoft Corporation 1984-2002. All rights
reserved.

>abc.cpp
>abc.cpp(12) : error C2352: 'Template<T>::f' : illegal
call of
>non-static member
>function
>        with
>        [
>            T=int
>        ]
>        abc.cpp(3) : see declaration of 'Template<T>::f'
>        with
>        [
>            T=int
>        ]

>But it's legal to call a non-static member function if
it's defined in
>a base class (see 9.3.1 in the standard), and Base (aka
Template<int>)
>is a base class of X.

>- Alan
>.



Tue, 06 Dec 2005 19:42:58 GMT  
 Bug in VC++ 2003 (base class name lookup issue?)

--------------------

Quote:

> Newsgroups: microsoft.public.dotnet.languages.vc
> Subject: Bug in VC++ 2003 (base class name lookup issue?)
> Date: 20 Jun 2003 02:08:06 -0700

> I'm getting an error compiling the following code, although I believe
> it is legal (and it is accepted by VC++ 2002 and by Comeau):

> template <typename T> struct Template
> {
>    void f();
> };

> struct Outer
> {
>    typedef Template<int> Base;

>    struct X : Base
>    {
>       void g() { Base::f(); } // Error here
>    };
> };

> When compiled with "cl -c abc.cpp" I get:

> Microsoft (R) 32-bit C/C++ Optimizing Compiler Version 13.10.3077 for
> 80x86
> Copyright (C) Microsoft Corporation 1984-2002. All rights reserved.

> abc.cpp
> abc.cpp(12) : error C2352: 'Template<T>::f' : illegal call of
> non-static member
> function
>         with
>         [
>             T=int
>         ]
>         abc.cpp(3) : see declaration of 'Template<T>::f'
>         with
>         [
>             T=int
>         ]

> But it's legal to call a non-static member function if it's defined in
> a base class (see 9.3.1 in the standard), and Base (aka Template<int>)
> is a base class of X.

> - Alan

Hi Alan,

This is indeed a bug in VC7.1 and has been fixed in the next release of the
compiler. For a workaround, you can do this:

  struct X : Base {
    typedef Base Xbase;
    void g() { Xbase::f(); }
  };

--
Tanveer Gani, Visual C++ Team
This posting is provided AS IS with no warranties, and confers no rights.



Mon, 12 Dec 2005 01:24:19 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. Koenig Lookup in VC++ 2003 Final Beta

2. VC++ .Net 2003 Final Beta Issue #2

3. VC++ 2003 c2.dll bug D2029

4. VC .NET 2003 l-value bug?

5. 2 bugs in VC++ 2003

6. VC++ 2003 template bug?

7. VC++ 2003 compiler bug

8. VC.NET 2003 IDE bug report

9. Very probably a bug in the code generator of VC++ 2003

10. class class-name: base-class : interface

11. Nested class name lookup problem

12. BUG report: VC++ 5.0 SP3 erroneously reports c2437 for virtual base classes

 

 
Powered by phpBB® Forum Software