廃止予定の警告を実装する1つの方法は、廃止予定のコンテキストから呼び出している場合を除いて、廃止された関数の呼び出しに対して警告を出すことです。このようにして、レガシーコードは、ノイズにしか掛からない警告を出さずにレガシーコードを呼び出すことができます。GCCで推奨されなくなった関数で廃止予定の警告を取り除くにはどうすればよいですか?
これは合理的な考え方であり、OS XのGCC 4.2(1)およびClang 4.0(2)とUbuntuのClang 3.0(3)の実装にも反映されています。
- (1):i686の-りんごdarwin11-LLVM-G ++ - 4.2(GCC)4.2.1(アップル社に基づきが5658を構築)(LLVM 2336.11.00を構築)
- (2): LLVM 3.0ベースのUbuntu clangバージョン3.0-6ubuntu3(tags/RELEASE_30/final)
- (3):LLVM 3.0に基づいて、 (3)タグ:Apple clangバージョン4.0(タグ/ Apple/clang-421.0.57)
しかし、私がUbuntuでGCC 4.6(4)でコンパイルすると、deprecatのすべての呼び出しで廃止予定の警告が表示されますコンテキストとは関係なく、これは機能の回帰ですか?他の動作をさせるために使用できるコンパイラオプションはありますか?
- (4):G ++(Ubuntuの/リナロ4.6.3-1ubuntu5)4.6.3
プログラム例:GCC 4.2から
int __attribute__((deprecated)) a() {
return 10;
}
int __attribute__((deprecated)) b() {
return a() * 2; //< I want to get rid of warnings from this line
}
int main() {
return b(); //< I expect a warning on this line only
}
出力(はい、私は同じ警告を2回受け取りますが、私はそれについて気にしません):
main.cpp: In function ‘int main()’:
main.cpp:10: warning: ‘b’ is deprecated (declared at main.cpp:5)
main.cpp:10: warning: ‘b’ is deprecated (declared at main.cpp:5)
GCC 4.6から
出力:
main.cpp: In function 'int b()':
main.cpp:6:9: warning: 'int a()' is deprecated (declared at main.cpp:1) [-Wdeprecated-declarations]
main.cpp:6:11: warning: 'int a()' is deprecated (declared at main.cpp:1) [-Wdeprecated-declarations]
main.cpp: In function 'int main()':
main.cpp:10:9: warning: 'int b()' is deprecated (declared at main.cpp:5) [-Wdeprecated-declarations]
main.cpp:10:11: warning: 'int b()' is deprecated (declared at main.cpp:5) [-Wdeprecated-declarations]
がどのように私はGCC 4.6を説得することができ、それは私のGCC 4.2と同じ出力を与えるべきだと?
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
int __attribute__((deprecated)) b() {
return a() * 2; //< I want to get rid of warnings from this line
}
#pragma GCC diagnostic pop
注:GCC 4.6以降でのみ動作
これは、FSF GCCではまったく機能しない可能性があります。あなたが見ている4.2の動作は、GCCへのAppleパッチです。確認のためにFSF GCC 4.2をどこにインストールしてもらえますか? – hvd
@hvdあなたが正しいです。私はそのテストを見たいですが、私は4.2を手にしていません:/ –