Fix compilation error with GCC on OSX (issue #490). (#491)

This commit is contained in:
Victor Costan 2017-11-30 08:05:38 -08:00 committed by Dominic Hamon
parent c45f01866b
commit 95a1435b81

View File

@ -73,22 +73,14 @@ BENCHMARK_NORETURN void PrintErrorAndDie(Args&&... args) {
#ifdef BENCHMARK_HAS_SYSCTL
#ifdef __GNUC__
// Suppress the warning generated by the C11 flexible array member below.
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wpedantic"
#endif
/// ValueUnion - A type used to correctly alias the byte-for-byte output of
/// `sysctl` with the result type it's to be interpreted as.
struct ValueUnion {
union DataT {
uint32_t uint32_value;
uint64_t uint64_value;
// FIXME (Maybe?): This is a C11 flexible array member, and not technically
// C++. However, all compilers support it and it allows for correct aliasing
// of union members from bytes.
char bytes[];
// For correct aliasing of union members from bytes.
char bytes[8];
};
using DataPtr = std::unique_ptr<DataT, decltype(&std::free)>;
@ -137,10 +129,6 @@ struct ValueUnion {
}
};
#ifdef __GNUC__
#pragma GCC diagnostic pop
#endif
ValueUnion GetSysctlImp(std::string const& Name) {
size_t CurBuffSize = 0;
if (sysctlbyname(Name.c_str(), nullptr, &CurBuffSize, nullptr, 0) == -1)
@ -177,7 +165,7 @@ bool GetSysctl(std::string const& Name, std::array<Tp, N>* Out) {
if (!Buff) return false;
*Out = Buff.GetAsArray<Tp, N>();
return true;
};
}
#endif
template <class ArgT>