This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
c++/3747: ambiguity between `T operator[](unsigned)` and `T* operator`
- To: gcc-gnats at gcc dot gnu dot org
- Subject: c++/3747: ambiguity between `T operator[](unsigned)` and `T* operator`
- From: jan at etpmod dot phys dot tue dot nl
- Date: 20 Jul 2001 15:12:23 -0000
- Reply-To: jan at etpmod dot phys dot tue dot nl
>Number: 3747
>Category: c++
>Synopsis: ambiguity between `T operator[](unsigned)` and `T* operator`
>Confidential: no
>Severity: critical
>Priority: medium
>Responsible: unassigned
>State: open
>Class: rejects-legal
>Submitter-Id: net
>Arrival-Date: Fri Jul 20 08:16:03 PDT 2001
>Closed-Date:
>Last-Modified:
>Originator: jan@etpmod.phys.tue.nl
>Release: gcc version 3.0
>Organization:
>Environment:
Linux 2.4.6,
Configured with: ../../src/egcs-3.0/configure --enable-version-specific-runtime-libs --prefix=/usr/local/egcs-3.0
>Description:
The attached code (file strtest.cpp) fails to compile with egcs version 3.0 (or with the head branch). This is a regression wrt 2.95.x
Gcc-3.0:pcjan:/home/jan/src>g++ -c strtest.cpp
strtest.cpp:6: choosing `char& A::operator[](unsigned int)' over `operator[]'
strtest.cpp:6: because worst conversion for the former is better than worst
conversion for the latter
The compiler is in doubt: it cannot choose between A.operator[](0) and
A.(operator const char*).`c-builtin[]`(0). IMHO the first conversion has preference and should be chosen.
>How-To-Repeat:
Compile the attached file strtest.cpp
>Fix:
This bug breaks existing code, I could not think of a transparent workaround. If `0' is replaced with `0u' (unsigned 0), the snippet compiles properly.
>Release-Note:
>Audit-Trail:
>Unformatted:
----gnatsweb-attachment----
Content-Type: text/x-c++src; name="strtest.cpp"
Content-Transfer-Encoding: base64
Content-Disposition: attachment; filename="strtest.cpp"
c3RydWN0IEEgewoJY2hhciBvcGVyYXRvcltdKHVuc2lnbmVkKSBjb25zdDsKCW9wZXJhdG9yIGNv
bnN0IGNoYXIqKCkgY29uc3Q7Cn07CkEgczsKY2hhciBjPXNbMHVdOwo=