Compile-time detection of deprecated API calls?
boost, c++, c++11, static-assert
Solution
With C++14 you will have that option :
#include <iostream>
void foo( int v ) { std::cout << v << " "; }
[[deprecated("foo with float is deprecated")]]
void foo( float v ) { std::cout << v << " "; }
[[deprecated("you should not use counter anymore")]]
int counter {};
int main() {
foo( ++counter );
foo( 3.14f );
}
Clang gives the compilation output (here) :
main.cpp:12:10: warning: 'counter' is deprecated [-Wdeprecated-declarations]
foo( ++counter );
^
main.cpp:9:5: note: 'counter' has been explicitly marked deprecated here
int counter {};
^
main.cpp:13:3: warning: 'foo' is deprecated [-Wdeprecated-declarations]
foo( 3.14f );
^
main.cpp:6:6: note: 'foo' has been explicitly marked deprecated here
void foo( float v ) { std::cout << v << " "; }
^
2 warnings generated.
Problem
Is there any new, cool feature in C++11 that allows us to detect at compile time whether an API now marked as deprecated is actually called by someone? From what I've read about the new `static_assert` feature it doesn't seem flexible enough to be used in that kind of analysis. But is there anything else we could use? Optionally, is there anything in boost allowing that kind of compile-time checking?