From 9d04c2b9e4f75c51a9427c534e896b9b68bfba55 Mon Sep 17 00:00:00 2001 From: fliiiix Date: Sat, 20 Jan 2024 10:41:32 +0100 Subject: [PATCH] [C++] Make code compile with -Wfloat-equal This will allow the code to be compiled with `-Wfloat-equal` as this would result in the folowing warning/error: vendor/flatbuffers/include/flatbuffers/base.h:465:69: error: comparing floating point with == or != is unsafe [-Werror,-Wfloat-equal] template inline bool IsTheSameAs(T e, T def) { return e == def; } But the way it is used in flatbuffers it is ok to compare floating points with ==. --- include/flatbuffers/base.h | 3 +++ 1 file changed, 3 insertions(+) diff --git a/include/flatbuffers/base.h b/include/flatbuffers/base.h index 97d76a6e645f..f8119cc71ebf 100644 --- a/include/flatbuffers/base.h +++ b/include/flatbuffers/base.h @@ -459,10 +459,13 @@ inline size_t PaddingBytes(size_t buf_size, size_t scalar_size) { return ((~buf_size) + 1) & (scalar_size - 1); } +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wfloat-equal" // Generic 'operator==' with conditional specialisations. // T e - new value of a scalar field. // T def - default of scalar (is known at compile-time). template inline bool IsTheSameAs(T e, T def) { return e == def; } +#pragma GCC diagnostic pop #if defined(FLATBUFFERS_NAN_DEFAULTS) && \ defined(FLATBUFFERS_HAS_NEW_STRTOD) && (FLATBUFFERS_HAS_NEW_STRTOD > 0)