Inappropriate Warning Cannot Be Turned Off

David Cogen cogen@ll.mit.edu
Mon Jun 5 13:06:00 GMT 2000


Yes, this really is a bug report. I have posted this several times, but always
with a respectful time has elapsed. The last time was a couple weeks
ago. 

Wouldn't someone in the know PLEASE respond to this?

(Please don't respond by telling me to fix this myself. I don't understand
compilers enough. My fix was to write an awk program to filter the compiler's
warning messages and remove this particular inappropriate warning (!). I'll
gladly contribute this "fix" to FSF or whomever, but I am sure this is not the
right way to fix this :)

Here goes:

-----

Example code fragment, when compiled, produces inappropriate warnings. And
there is no way to disable these warnings.

Compiler: gcc2.95.2
System: SunOS 5.7

Compiled as follows:

  g++ -o test test.cc

The following program:

  #include <iostream.h>
  #include <fstream.h>

  template <class T>
  struct Auto0 {

  public:

    Auto0 () : mValue (0) {}

    operator const T & () const {return mValue;}

    operator T & () {return mValue;}

  private:

    T mValue;

  };

  int main ()
  {
    Auto0 <int> ab;
    cout << "ab = " << ab << " ab+1=" << ab+1 << "\n";
    ++ ab;
    cout << "after incr, ab = " << int(ab) << "\n";
    const Auto0 <int> cd;
    cout << "cd = " << cd << " cd+1=" << cd+1 << "\n";
  }

Produces warnings which are inappropriate:

  test.cc: In function `int main()':
  test.cc:56: warning: choosing `Auto0<int>::operator int &()' over `Auto0<int>::operator const int &() const'
  test.cc:56: warning:   for conversion from `Auto0<int>' to `int'
  test.cc:56: warning:   because conversion sequence for the argument is better
  test.cc:56: warning: choosing `Auto0<int>::operator int &()' over `Auto0<int>::operator const int &() const'
  test.cc:56: warning:   for conversion from `Auto0<int>' to `int'
  test.cc:56: warning:   because conversion sequence for the argument is better
  test.cc:58: warning: choosing `Auto0<int>::operator int &()' over `Auto0<int>::operator const int &() const'
  test.cc:58: warning:   for conversion from `Auto0<int>' to `int'
  test.cc:58: warning:   because conversion sequence for the argument is better

  Compilation finished at Tue Apr 25 13:15:53

-- DavidC



More information about the Gcc-bugs mailing list