Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
449 views
in Technique[技术] by (71.8m points)

c++ - How can I get rid of deprecated warnings in deprecated functions in GCC?

One way to implement deprecation warnings is to produce warnings on calls to deprecated functions, unless you are calling from a deprecated context. This way legacy code can call legacy code without producing warnings that only amount to noise.

This is a reasonable line of thinking, and it is reflected in the implementations I see in GCC 4.2 (1) and Clang 4.0 (2) on OS X as well as Clang 3.0 (3) on Ubuntu.

  • (1): i686-apple-darwin11-llvm-g++-4.2 (GCC) 4.2.1 (Based on Apple Inc. build 5658) (LLVM build 2336.11.00)
  • (2): Apple clang version 4.0 (tags/Apple/clang-421.0.57) (based on LLVM 3.1svn)
  • (3): Ubuntu clang version 3.0-6ubuntu3 (tags/RELEASE_30/final) (based on LLVM 3.0)

However, when I compile with GCC 4.6 (4) on Ubuntu, I get deprecated warnings for all invocations of deprecated functions, independently of context. Is this a regression in functionality? Are there compiler options I can use to get the other behavior?

  • (4): g++ (Ubuntu/Linaro 4.6.3-1ubuntu5) 4.6.3

Example program:

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
}

Output from GCC 4.2 (Yes, I do get the same warning twice. I don't care about that, though):

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)

Output from 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]

How can I convince GCC 4.6 that it should give me the same output as GCC 4.2?

question from:https://stackoverflow.com/questions/13459602/how-can-i-get-rid-of-deprecated-warnings-in-deprecated-functions-in-gcc

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

-Wno-deprecated will remove all deprecated warnings


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...