Re: Old Meyers C++ compiler test no longer valid?
On 16 Jul., 19:33, Russ Bryan <rbryan.nay...@gmail.com> wrote:
const class {
public:
template <class T>
operator T*() const {return 0;}
template <class C, class T>
operator T C::*() const {return 0;}
} null = {};
I don't know why this compiles. "null" has internal linkage, but its
type has no linkage (unnamed class). It seems to violate 3.5/8.
class A {
public:
int f (char, int);
int f (char, double);
void f (const char *) const;
};
class B {};
int main() {
int (A::*pmf)(char, int) = &A::f;
pmf = null;
int (A::*pmf2)(char, double) = &A::f;
pmf2 = null;
void (A::*pmf3)(const char*) const = &A::f;
pmf3 = null; <<< No user-defined operator can perform this
conversion
void (B::*pmf4)() const = null; <<< No user-defined operator can
perform this conversion
}
Here is what i think is going on: While argument deduction is done, T
is deduced to be
"void(const char*)const" and "void()const"
respectively. A const qualifier may only be part of a function type
for a member pointer. But here, it's part of a type being a "naked"
function type. This qualifies as a deduction failure (although that
case is not part of the list in 14.8.2/2).
I wish the Standard was clearer on this matter. Clearly, T is part of
a member pointer type. But it's also a "stand-alone type" referred to
by "T" and would violate 8.3.5/4. Some example in that paragraph could
clear up the matter.
--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]