Fix -Wdeprecated-declarations warning once more. (#1256)

In #1238, one of MemoryManager's Stop methods was marked as deprecated
and this method is used in the same header. This change generated
-Wdeprecated-declarations warning on every file that includes
"benchmark.h". Use gcc's diagnostics to fix this warning.
This commit is contained in:
Byoungchan Lee 2021-10-21 18:10:38 +09:00 committed by GitHub
parent 1e3ab7fa43
commit 80d70ddd94
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 16 additions and 14 deletions

View File

@ -242,12 +242,19 @@ BENCHMARK(BM_test)->Unit(benchmark::kMillisecond);
#if defined(__GNUC__) || defined(__clang__)
#define BENCHMARK_BUILTIN_EXPECT(x, y) __builtin_expect(x, y)
#define BENCHMARK_DEPRECATED_MSG(msg) __attribute__((deprecated(msg)))
#define BENCHMARK_DISABLE_DEPRECATED_WARNING \
_Pragma("GCC diagnostic push") \
_Pragma("GCC diagnostic ignored \"-Wdeprecated-declarations\"")
#define BENCHMARK_RESTORE_DEPRECATED_WARNING \
_Pragma("GCC diagnostic pop")
#else
#define BENCHMARK_BUILTIN_EXPECT(x, y) x
#define BENCHMARK_DEPRECATED_MSG(msg)
#define BENCHMARK_WARNING_MSG(msg) \
__pragma(message(__FILE__ "(" BENCHMARK_INTERNAL_TOSTRING( \
__LINE__) ") : warning note: " msg))
#define BENCHMARK_DISABLE_DEPRECATED_WARNING
#define BENCHMARK_RESTORE_DEPRECATED_WARNING
#endif
#if defined(__GNUC__) && !defined(__clang__)
@ -339,7 +346,9 @@ class MemoryManager {
virtual void Stop(Result* result) = 0;
// FIXME(vyng): Make this pure virtual once we've migrated current users.
BENCHMARK_DISABLE_DEPRECATED_WARNING
virtual void Stop(Result& result) { Stop(&result); }
BENCHMARK_RESTORE_DEPRECATED_WARNING
};
// Register a MemoryManager instance that will be used to collect and report

View File

@ -378,10 +378,7 @@ void RunBenchmarks(const std::vector<BenchmarkInstance>& benchmarks,
// Disable deprecated warnings temporarily because we need to reference
// CSVReporter but don't want to trigger -Werror=-Wdeprecated-declarations
#if defined(__GNUC__) || defined(__clang__)
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
#endif
BENCHMARK_DISABLE_DEPRECATED_WARNING
std::unique_ptr<BenchmarkReporter> CreateReporter(
std::string const& name, ConsoleReporter::OutputOptions output_opts) {
@ -398,9 +395,7 @@ std::unique_ptr<BenchmarkReporter> CreateReporter(
}
}
#ifdef __GNUC__
#pragma GCC diagnostic pop
#endif
BENCHMARK_RESTORE_DEPRECATED_WARNING
} // end namespace

View File

@ -321,7 +321,9 @@ void BenchmarkRunner::DoOneRepetition() {
manager->WaitForAllThreads();
manager.reset();
BENCHMARK_DISABLE_DEPRECATED_WARNING
memory_manager->Stop(memory_result);
BENCHMARK_RESTORE_DEPRECATED_WARNING
}
// Ok, now actually report.

View File

@ -384,10 +384,8 @@ int SetSubstitutions(
// Disable deprecated warnings temporarily because we need to reference
// CSVReporter but don't want to trigger -Werror=-Wdeprecated-declarations
#if defined(__GNUC__) || defined(__clang__)
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
#endif
BENCHMARK_DISABLE_DEPRECATED_WARNING
void RunOutputTests(int argc, char* argv[]) {
using internal::GetTestCaseList;
benchmark::Initialize(&argc, argv);
@ -446,9 +444,7 @@ void RunOutputTests(int argc, char* argv[]) {
internal::GetResultsChecker().CheckResults(csv.out_stream);
}
#ifdef __GNUC__
#pragma GCC diagnostic pop
#endif
BENCHMARK_RESTORE_DEPRECATED_WARNING
int SubstrCnt(const std::string& haystack, const std::string& pat) {
if (pat.length() == 0) return 0;