-Wignored-qualifiers, a rock and a hard place
Magnus Fromreide
gcc@lysator.liu.se
Fri Dec 10 16:52:00 GMT 2010
Hello.
I have inherited a whole heap of interfaces that, in principle, look like
class Base {
public:
virtual ~Base() { }
virtual const int method() = 0;
};
and the knowledge that there are many users of this code, similar to
class Derived : public Base {
public:
const int method() { /* Do something */ return 0; }
};
Now, I think -Wignored-qualifiers i a relly nice debug option so I compile
the above code and - as expected - I get warnings:
warning: type qualifiers ignored on function return type [-Wignored-qualifiers]
for the 'const int'. Now that is quite reasonable so now I want to fix the code
that I control, i.e. only Base. (Ok, I would like to fix all Derived's as
well but right now that is impossible as I don't even know where they all are).
Since the warning says the type qualifier is ignored I would guess that I could
just remove it in Base but when I change Base to
class Base {
public:
virtual ~Base() { }
virtual int method() = 0;
};
and recompiles I end up with
warning: type qualifiers ignored on function return type [-Wignored-qualifiers]
error: conflicting return type specified for 'virtual const int Derived::method()'
error: overriding 'virtual int Base::method()'
so obviously the const ain't that ignored after all.
Now, my question is how I can remove that const in an incremental way so that
I don't have to use a flag day but can shift all of those 6000 warnings down
to the not yet updated uses in the Derived instances.
More information about the Gcc-help
mailing list