Inappropriate Warning Cannot Be Turned Off
David Cogen
cogen@ll.mit.edu
Wed May 17 04:16:00 GMT 2000
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