BUG (VC7.1 and Whidbey): compiler allows access to private definitions in some cases

M

Maxim Yegorushkin

Code to reproduce the bug (Comeau refuses to compile the code, but VC has
no complain about it):

template<class T, class S>
class M
{
private:
struct m_tag;
};

template<class T>
struct is_m
{
template<class U>
static char is_m_helper(U*, typename U::m_tag*);

static double is_m_helper(...);

static T* t;
enum { value = sizeof(is_m_helper(t, 0)) == sizeof(char) };
};

struct A : M<void, void> {};
struct B;
class C : private M<void, void> {};

typedef char a[is_m<A>::value]; // must not compile
typedef char b[!is_m<B>::value];
typedef char c[is_m<C>::value]; // must not compile

m_tag is a private nested struct declaration. How does it come out that
is_m_helper() has access to it (after SFINAE has been applied)?
 

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