Reputation: 11317
Recently, we discovered that one of our external libraries (DLib) is suppressing warnings at a global level. Writing the following code gives us a warning:
[[deprecated]] int findDeprecated() { return 42; }
int test = findDeprecated();
Including a dlib header suppresses the warning:
#include <dlib/matrix.h>
[[deprecated]] int findDeprecated() { return 42; }
int test = findDeprecated();
Having to trigger all of these warnings in order to vet our external libraries is very cumbersome and not easy to integrate in our codebase. Hence we would like to create a new test that conceptually looks like:
#include <dlib>
#include <boost>
static_assert(getWarningLevel(4996) == 4, "Deprecated Warning Was suppressed");
However, from searching around, we can't find a way to request the warning level as search engines always tell us how to enable the warning. Does a way exist in order to retrieve the warning level?
Some restrictions to the answer:
Upvotes: 0
Views: 126
Reputation: 51894
You can save and restore your warning level(s) with:
#pragma warning(push) // Save current warning state
#include <offendingheaderfile.h>
#pragma warning(pop) // Restore saved warning state
Upvotes: 3