Skip to content

Commit

Permalink
Fix build with recent version of GCC (#2661)
Browse files Browse the repository at this point in the history
Without this patch, the definition of the custom deleter would drop the attributes of the `fclose` function.

BUG=#2660
  • Loading branch information
LucasChollet authored Aug 12, 2024
1 parent 79ceb4c commit 19577c1
Showing 1 changed file with 6 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,13 @@ void SetRandomInput(const uint32_t random_seed,
}

#if !defined(GENERIC_BENCHMARK_USING_BUILTIN_MODEL)

struct FileCloser {
void operator()(FILE* file) { fclose(file); }
};

bool ReadFile(const char* file_name, void* buffer, size_t buffer_size) {
std::unique_ptr<FILE, decltype(&fclose)> file(fopen(file_name, "rb"), fclose);
std::unique_ptr<FILE, FileCloser> file(fopen(file_name, "rb"));

const size_t bytes_read =
fread(buffer, sizeof(char), buffer_size, file.get());
Expand Down

0 comments on commit 19577c1

Please sign in to comment.