C++ 14
Contents
Deprecated
We can place this attribute before a function and a compile time warning will appear.File: depr1.cpp
#include <iostream> #include <type_traits> [[deprecated]] void old_method1() { } [ [deprecated("Use new_method instead")] ] void old_method2() { } int main() { old_method1() ; old_method2() ; return 0; }
$ g++ depr1.cpp ; ./a.exe
depr1.cpp: In function ‘int main()’:
depr1.cpp:17:14: warning: ‘void old_method1()’ is deprecated [-Wdeprecated-declarations]
17 | old_method1() ;
| ~~~~~~~~~~~^~
depr1.cpp:5:6: note: declared here
5 | void old_method1()
| ^~~~~~~~~~~
depr1.cpp:18:14: warning: ‘void old_method2()’ is deprecated: Use new_method instead [-Wdeprecated-declarations]
18 | old_method2() ;
| ~~~~~~~~~~~^~
depr1.cpp:10:6: note: declared here
10 | void old_method2()
| ^~~~~~~~~~~
Note that if the function is not called/used then the warnings
do not appear.