GCC 4.3で初めてCCCコードをコンパイルしたとき(私は、4.1、4.0、3.4の警告なしで、-Wall -Wextra
オプションで正常にコンパイルした後)、突然フォームwarning: type qualifiers ignored on function return type
のエラーの束。Pedantic gcc警告:関数の戻り値のタイプ修飾子
はtemp.cpp
考えてみましょう:
class Something
{
public:
const int getConstThing() const {
return _cMyInt;
}
const int getNonconstThing() const {
return _myInt;
}
const int& getConstReference() const {
return _myInt;
}
int& getNonconstReference() {
return _myInt;
}
void setInt(const int newValue) {
_myInt = newValue;
}
Something() : _cMyInt(3) {
_myInt = 2;
}
private:
const int _cMyInt;
int _myInt;
};
はg++ temp.cpp -Wextra -c -o blah.o
の実行:
temp.cpp:4: warning: type qualifiers ignored on function return type
temp.cpp:7: warning: type qualifiers ignored on function return type
誰かがC++標準に違反している私が間違っているのを教えすることはできますか?私は値で返ってくると、先導const
は余分ですが、私はなぜそれを使って警告を生成する必要があるのか理解できないと思います。私がconstを離れなければならない他の場所はありますか?
このような質問と回答を参照してください:http://stackoverflow.com/questions/1607188/why-is-type-qualifier-on-return-type-is-meaningless –
これまでのような警告が表示されています私はコード内で何が起こっていたのか理解しようと数分を費やしました。おそらく、より良いエラー報告は物事をスピードアップするでしょう。 'warning:type修飾子は関数の型を無視して型を返す'の代わりに、 'warning:' valueで返すときにconst修飾子を付けないでください 'のようになります。 – Avio