this code:
class bar {
public:
    operator int&() { return f; }
    operator const int&() const { return f; }
    int f;
    };

int main() {
    const bar* cb;
    const int& cx = *cb;
    bar* b;
    int& x = *b;
    switch(*cb) {}
    switch(*b) {}
    return 0;
    }

gets you:
~/ootbc/personal/ivan$ g++ foo.cc
foo.cc: In function ‘int main()’:
foo.cc:13: error: ambiguous default type conversion from ‘const bar’
foo.cc:13: error:   candidate conversions include ‘bar::operator int&()’ and
‘bar::operator const int&() const’
foo.cc:14: error: ambiguous default type conversion from ‘bar’
foo.cc:14: error:   candidate conversions include ‘bar::operator int&()’ and
‘bar::operator const int&() const’

Note that it reports ambiguity both when the source is const and only one
conversion (the "const int&() const" one) is possible, and also when the source
is not const even though a conversion not involving constifying is preferred to
one that does constify. Not sure whether this counts as one or two bugs.


Here's what Comeau says:
Comeau C/C++ 4.3.10.1 (May 29 2008 09:37:15) for ONLINE_EVALUATION_BETA1
Copyright 1988-2008 Comeau Computing.  All rights reserved.
MODE:strict errors C++ C++0x_extensions

"ComeauTest.c", line 10: warning: variable "cb" is used before its value is set
      const int& cx = *cb;
                       ^

"ComeauTest.c", line 12: warning: variable "b" is used before its value is set
      int& x = *b;
                ^


-- 
           Summary: bogus ambiguity reported
           Product: gcc
           Version: 4.3.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: igodard at pacbell dot net


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=37108

Reply via email to