How to add a line or message in a deprecated function
I have a say void function foo()
. I condemn this as old func: -
void foo()__attribute__ ((deprecated));
new func: -
void FOO();
Now I want to add a message along with this in the old function that "new function is in use FOO
", which can be seen along with the warning message we get after compiling the code.
How to do it.
+3
source to share
3 answers
You can use the attribute [[deprecated(msg)]]
, which is the standard way to do it (since C ++ 14).
[[deprecated("do not use")]]
void f()
{}
int main(){
f();
}
conclusion clang++
:
warning: 'f' is deprecated: do not use [-Wdeprecated-declarations]
f();
^
note: 'f' has been explicitly marked deprecated here
void f()
^
1 warning generated.
conclusion g++
:
In function ‘int main()’:
warning: ‘void f()’ is deprecated (declared at test.cpp:2): do not use [-Wdeprecated-declarations]
f();
^
warning: ‘void f()’ is deprecated (declared at test.cpp:2): do not use [-Wdeprecated-declarations]
f();
+3
source to share