This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
Inappropriate Warning Cannot Be Turned Off
- To: gcc-bugs at gcc dot gnu dot org
- Subject: Inappropriate Warning Cannot Be Turned Off
- From: David Cogen <cogen at ll dot mit dot edu>
- Date: Wed, 17 May 2000 07:15:27 -0400 (EDT)
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