I
Ivan A. Kosarev
Hello,
There are three similar programs below. All of these use typedef names,
qualified identifiers, class names and name lookup mechanism in various
contexts. I found that most respect C++ compilers differ significantly in
interpreting the code. So, could anyone pick a correct behavior a conformant
compiler should follow for each of the cases?
Please note that I used the following compilers and command-line options:
EDG 3.6 --strict
MSVC 13.10.3077 /Za
GCC 3.4.4 --ansi
Thank you.
// 1
class C {
public:
int f();
};
int main() {
typedef C T;
C c;
// EDG MSVC GCC
c.~T(); // ok ok ok
c.T::~T(); // ok ok ok
c.T::C::f(); // ok fails ok
c.T::T::f(); // fails fails fails
}
// 2
class C {
public:
typedef int T;
int f();
};
int main() {
typedef C T;
C c;
// EDG MSVC GCC
c.~T(); // ok ok fails
c.T::~T(); // ok fails fails
c.T::C::f(); // ok fails fails
c.T::T::f(); // fails fails fails
}
// 3
class T {
public:
int f();
};
class C : public T {
public:
typedef int T;
};
int main() {
typedef C T;
C c;
// EDG MSVC GCC
c.~T(); // ok ok fails
c.T::~T(); // fails ok fails
c.T::C::f(); // fails fails fails
c.T::T::f(); // fails fails fails
}
There are three similar programs below. All of these use typedef names,
qualified identifiers, class names and name lookup mechanism in various
contexts. I found that most respect C++ compilers differ significantly in
interpreting the code. So, could anyone pick a correct behavior a conformant
compiler should follow for each of the cases?
Please note that I used the following compilers and command-line options:
EDG 3.6 --strict
MSVC 13.10.3077 /Za
GCC 3.4.4 --ansi
Thank you.
// 1
class C {
public:
int f();
};
int main() {
typedef C T;
C c;
// EDG MSVC GCC
c.~T(); // ok ok ok
c.T::~T(); // ok ok ok
c.T::C::f(); // ok fails ok
c.T::T::f(); // fails fails fails
}
// 2
class C {
public:
typedef int T;
int f();
};
int main() {
typedef C T;
C c;
// EDG MSVC GCC
c.~T(); // ok ok fails
c.T::~T(); // ok fails fails
c.T::C::f(); // ok fails fails
c.T::T::f(); // fails fails fails
}
// 3
class T {
public:
int f();
};
class C : public T {
public:
typedef int T;
};
int main() {
typedef C T;
C c;
// EDG MSVC GCC
c.~T(); // ok ok fails
c.T::~T(); // fails ok fails
c.T::C::f(); // fails fails fails
c.T::T::f(); // fails fails fails
}