public inbox for gcc-prs@sourceware.org
help / color / mirror / Atom feed
* c++/4556: g++ reports an error for operator[] related conversions
@ 2001-10-12 8:46 apataki
0 siblings, 0 replies; 2+ messages in thread
From: apataki @ 2001-10-12 8:46 UTC (permalink / raw)
To: gcc-gnats
>Number: 4556
>Category: c++
>Synopsis: g++ reports an error for operator[] related conversions
>Confidential: no
>Severity: serious
>Priority: medium
>Responsible: unassigned
>State: open
>Class: rejects-legal
>Submitter-Id: net
>Arrival-Date: Fri Oct 12 08:46:00 PDT 2001
>Closed-Date:
>Last-Modified:
>Originator: Andras Pataki
>Release: gcc-3.0.1
>Organization:
>Environment:
dbgloss2:~/try$ /usr/gnu/gcc-3.0.1/bin/gcc -v
Reading specs from /usr/gnu/gcc-3.0.1/lib/gcc-lib/sparc-sun-solaris2.6/3.0.1/specs
Configured with: ../gcc-3.0.1/configure --prefix=/usr/gnu/gcc-3.0.1
Thread model: posix
gcc version 3.0.1
dbgloss2:~/try$ uname -a
SunOS dbgloss2 5.6 Generic_105181-23 sun4u sparc SUNW,Ultra-80
dbgloss2:~/try$
>Description:
The following simple program fails to compile:
dbgloss2:~/try$ cat 6.cc
class X
{
public:
char &operator[](unsigned i);
operator const char *();
};
void f()
{
X x;
int i = 0;
char c = x[i];
}
dbgloss2:~/try$ /usr/gnu/gcc-3.0.1/bin/g++ -c 6.cc
6.cc: In function `void f()':
6.cc:14: choosing `char& X::operator[](unsigned int)' over `operator[]'
6.cc:14: because worst conversion for the former is better than worst
conversion for the latter
dbgloss2:~/try$ echo $?
1
dbgloss2:~/try$
For the x[i] expression's interpretation the two options are:
char &X::operator[](unsigned i)
requiring an integral conversion for 'i' (int -> unsigned)
built in operator[] for char *
requiring a user defined conversion for X -> const char *
Since the latter requires a user defined conversion, it is less preferable than the former.
So I believe the compiler should pick the former and not return an error message and exit with an exit status 1.
>How-To-Repeat:
See description
>Fix:
The workaround it to declare 'i' as an 'int' not as an 'unsigned'.
This is painful for a large codebase though.
>Release-Note:
>Audit-Trail:
>Unformatted:
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: c++/4556: g++ reports an error for operator[] related conversions
@ 2001-10-16 5:31 billingd
0 siblings, 0 replies; 2+ messages in thread
From: billingd @ 2001-10-16 5:31 UTC (permalink / raw)
To: apataki, gcc-bugs, gcc-prs, jan, nobody
Synopsis: g++ reports an error for operator[] related conversions
State-Changed-From-To: open->closed
State-Changed-By: billingd
State-Changed-When: Tue Oct 16 05:31:18 2001
State-Changed-Why:
Duplicate of PR 3747
http://gcc.gnu.org/cgi-bin/gnatsweb.pl?cmd=view&pr=4556&database=gcc
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2001-10-16 5:31 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2001-10-12 8:46 c++/4556: g++ reports an error for operator[] related conversions apataki
2001-10-16 5:31 billingd
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).