This is the mail archive of the gcc-prs@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]

c++/328: Wrong warning: choosing 'conversion operator' over 'const conversion operator'



>Number:         328
>Category:       c++
>Synopsis:       Wrong warning: choosing 'conversion operator' over 'const conversion operator'
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    unassigned
>State:          open
>Class:          rejects-legal
>Submitter-Id:   net
>Arrival-Date:   Fri Jun 16 10:06:00 PDT 2000
>Closed-Date:
>Last-Modified:
>Originator:     Ruediger Franke
>Release:        gcc version 2.95.2 19991024 (release)
>Organization:
>Environment:
Cygwin 1.1.2
>Description:
$ gcc gcc295.cpp
gcc295.cpp: In function `int main()':
gcc295.cpp:27: warning: choosing `DoubleWrapper::operator double &()' over `DoubleWrapper::operator const double &() const'
gcc295.cpp:27: warning:   for conversion from `DoubleWrapper' to `const double &'
gcc295.cpp:27: warning:   because conversion sequence for the argument is better
gcc295.cpp:17: warning: in passing argument 1 of `func_const(const double &)'

Gcc 2.95 produces this warning about chosing a non-const conversion operator over a constant one.
    I'm frequently using a similar wrapper class in an optimization software I've been writing for a couple of years now (www.tu-ilmenau.de/~hqp). With gcc 2.95 the warning is emitted very often during the compilation and several users asked me if there was a problem in my code. But I think this is a gcc problem.
    In mine the code of the attached example is correct and gcc should not complain about it, at least not when invoked in default mode. 

Can you suppress the warning in a new release?
Can you tell me how to avoid this warning with the current release?

Thank you for your help in advance!
Ruediger
>How-To-Repeat:
// gcc295.cpp
class DoubleWrapper {
  double _d;
public:
  DoubleWrapper(double val) :_d(val) {};
  operator double&() {return _d;}
  operator const double&() const {return _d;}
};

void func(double &d)
{
  d = 3.0;
}

void func_const(const double &d)
{
  double v4 = d;
  v4 = v4;
}

int main()
{
  DoubleWrapper w(1.0);
  const DoubleWrapper cw(2.0);
  func(w);
  func_const(w);
  func_const(cw);
  return 0;
}
>Fix:
not known
>Release-Note:
>Audit-Trail:
>Unformatted:

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