This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
c++/3830: compile error, if a class has operator[] and operator char*()
- To: gcc-gnats at gcc dot gnu dot org
- Subject: c++/3830: compile error, if a class has operator[] and operator char*()
- From: martin dot gerbershagen at icn dot siemens dot de
- Date: 26 Jul 2001 12:37:26 -0000
- Reply-To: martin dot gerbershagen at icn dot siemens dot de
>Number: 3830
>Category: c++
>Synopsis: compile error, if a class has operator[] and operator char*()
>Confidential: no
>Severity: serious
>Priority: medium
>Responsible: unassigned
>State: open
>Class: rejects-legal
>Submitter-Id: net
>Arrival-Date: Thu Jul 26 05:46:01 PDT 2001
>Closed-Date:
>Last-Modified:
>Originator: Martin Gerbershagen
>Release: gcc-3.0
>Organization:
>Environment:
>Description:
When the attached code is compiled with g++ -c the following
error message is issued:
bug.C: In function `void x()':
bug.C:20: choosing `char& A::operator[](unsigned int)' over `operator[]'
bug.C:20: because worst conversion for the former is better than worst
conversion for the latter
bug.C:20: choosing `char& A::operator[](unsigned int)' over `operator[]'
bug.C:20: because worst conversion for the former is better than worst
conversion for the latter
This error is wrong, the code is legal code.
>How-To-Repeat:
class A {
char *p;
public:
char operator[](unsigned int i) const {
return p[i];
}
char& operator[](unsigned int i) {
return p[i];
}
operator char*() {
return p;
}
operator const char*() const {
return p;
}
};
void x() {
A a;
char c = a[1];
}
>Fix:
>Release-Note:
>Audit-Trail:
>Unformatted: