Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

[[deprecated]] attribute

Use case

Mark old analysis APIs for removal.

Explanation

[[deprecated]] generates compiler warnings when deprecated items are used.

Code

#include <cstdint>
#include <iostream>

[[deprecated("Use analyzeV2() instead.")]]
void analyze(uint64_t addr) {
  std::cout << "Old analysis: 0x" << std::hex << addr << "\n";
}

void analyzeV2(uint64_t addr) {
  std::cout << "New analysis: 0x" << std::hex << addr << "\n";
}

int main() {
  analyzeV2(0x10001000);

  // Uncomment to see deprecation warning.
  // analyze(0x10001000);
  return 0;
}

View on GitHub.

Output

$ ./src/c++14/build/deprecated-attribute
New analysis: 0x10001000