This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

GCC-3.0: possible regression


    Hello,

The following code compiles with 2.95.3, but not with 3.0. Before filing
a bug report, I would like your opinion what the standard has to say
about it (I did not find a previous related report). What's wrong: the
code or 3.0?

#include <cstddef>
struct MyString
{
        char operator [](size_t) const;
        char& operator [](size_t);
        operator const char*() const;
};

main()
{
        MyString s;
        char c = s[0];
        return 0;
}

Compiler output follows:

jan@gum03:/real-home/jan > g++ -c test.cpp
test.cpp: In function `int main()':
test.cpp:12: choosing `char& MyString::operator[](unsigned int)' over
   `operator[]'
test.cpp:12:   because worst conversion for the former is better than
worst
   conversion for the latter

I understand what's going on, but had expected the const-version of the
[]-operator to be chosen, like with 2.95.3.

Opinions?

    Greetings, Jan.

PS: Please cc me. Thanks.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]