BUG: C2352 with template base class (VS .NET 2003)

W

Werner Henze

Hi folks,

I found a bug in VS .NET 2003. When compiling the following code with FAIL defined
I get an error C2352
'B<T>::g::B<T>::g': Unzulässiger Aufruf einer nicht statischen Memberfunktion
with
[
T=COuter::Element *
]
and
[
T=COuter::Element *
]

Since g is not static I believe this is a compiler error. It works with the two
workarounds presented for f and f2. The error does not occur if FAIL is not
defined.

template <class T> class B {
public:
virtual bool f() const { return true; }
virtual bool g() const { return true; }
};

#undef FAIL
#define FAIL

#ifdef FAIL
class COuter
{
#endif
class Element {
};
typedef B<Element *> B_2;
class CInner : public B_2
{
// These work
virtual bool f () const { return B<Element *>::f(); }
virtual bool f2() const { return __super::f(); }
// This fails
virtual bool g () const { return B_2::g(); }
};
#ifdef FAIL
};
#endif

Kind regards,
Werner Henze
 
B

Bo Persson

Werner Henze said:
Hi folks,

I found a bug in VS .NET 2003. When compiling the following code with FAIL defined
I get an error C2352
'B<T>::g::B<T>::g': Unzulässiger Aufruf einer nicht statischen Memberfunktion
with
[
T=COuter::Element *
]
and
[
T=COuter::Element *
]

Since g is not static I believe this is a compiler error. It works with the two
workarounds presented for f and f2. The error does not occur if FAIL is not
defined.

template <class T> class B {
public:
virtual bool f() const { return true; }
virtual bool g() const { return true; }
};

#undef FAIL
#define FAIL

#ifdef FAIL
class COuter
{
#endif
class Element {
};
typedef B<Element *> B_2;

You cannot instantiate the template B with a local class. If you move
these three lines to global scope, it works.

That is what happens when you remove COuter!

class CInner : public B_2
{
// These work
virtual bool f () const { return B<Element *>::f(); }
virtual bool f2() const { return __super::f(); }
// This fails
virtual bool g () const { return B_2::g(); }
};
#ifdef FAIL
};
#endif

Kind regards,
Werner Henze


Bo Persson
(e-mail address removed)
 
H

Holger Grund

};
You cannot instantiate the template B with a local class. If you move
these three lines to global scope, it works.
I don't think that this is entirely correct. B is instantiated on
Element*
and not on Element. Furthermore, Element is not a local class.
Classes in functions cannot be used as template arguments. This
is not true for nested classes.

IMHO the code demonstrates a compiler bug.

-hg
 
W

Werner Henze

OK, let's assume your statement is correct. Then why don't I get an error on
typedef B<Element *> B_2;
and on
class CInner : public B_2
and on
virtual bool f () const { return B<Element *>::f(); }
?
Either way I think there is a bug in the VC++ compiler.

Kind regards,
Werner Henze
 
K

Keiji Oenoki [MSFT]

Hi Werner,
Thank you for your report. It does look like a compiler bug. The latest
internal build of the compiler can compile your code without any issues.

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


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

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