Search code examples
c++clangdeprecation-warning

How do I suppress deprecation warnings for function parameters?


I previously used such pragmas, which I seem to recall worked both with GCC (ubuntu) and clang (macos). They seem to be effective to suppress warning from header #includes.

// test.cpp
struct [[deprecated]] Foo {};

#pragma clang push
#pragma clang ignored "-Wdeprecated-declarations"

int main() {
  auto foo_fun = [](const Foo &f) {};
  foo_fun(Foo());
}
#pragma clang pop

However, it does not seem to work when the deprecated type occurs as a lambda or plain function parameter, when compiled with clang -std=c++14 -o wat test.cpp. The compiler version is Apple clang version 12.0.0 (clang-1200.0.32.29)

What do I do to suppress deprecation warning in these contexts?


Solution

  • You are missing a diagnostic keyword in your pragma declarations:

    #pragma clang diagnostic push
    #pragma clang diagnostic ignored "-Wdeprecated-declarations"
    
    ...
    
    #pragma clang diagnostic pop