c++/9437: template function parameter `T*' shouldn't match pointers to members

martin@xemacs.org martin@xemacs.org
Fri Jan 24 20:12:00 GMT 2003


>Number:         9437
>Category:       c++
>Synopsis:       template function parameter `T*' shouldn't match pointers to members
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    unassigned
>State:          open
>Class:          accepts-illegal
>Submitter-Id:   net
>Arrival-Date:   Fri Jan 24 19:46:00 UTC 2003
>Closed-Date:
>Last-Modified:
>Originator:     Martin Buchholz
>Release:        g++ (GCC) 3.3 20030122 (prerelease)
>Organization:
>Environment:
Linux x86
>Description:
The source file below should fail to compile
with something like `no conversion to int A::*',
as it does with icc and Comeau C++.

The standard is not completely clear on this, but
here is a rationale for why accepting the code is wrong:

If `T*' matches `int A::*', then what type is T??
`int A::' is not a type, and T cannot be int, since 
the types `int *' and `int A::*' are very different.

A pointer to member is not a pointer.

Code:
----------------------------------------------------
struct
{
  template <typename T>
  operator T* () const { return static_cast<T*> (0); }
} null;

struct A { int i; };

static void f (int A::* pmi) { }

int main () { f (null); }
>How-To-Repeat:
Compile above code with `g++ null_ptr.c'.
It incorrectly compiles without warning or error.
>Fix:

>Release-Note:
>Audit-Trail:
>Unformatted:



More information about the Gcc-bugs mailing list