Small patch to handle -Wfloat-equal warnings

https://groups.google.com/d/msg/protobuf/H8_D1hfg3p4/A2oPHdfUAgAJ
This commit is contained in:
senhalil 2019-04-08 20:02:04 +02:00 committed by Adam Cozzette
parent 27228494c3
commit 97e7ddc015

View File

@ -177,6 +177,10 @@ bool EmitFieldNonDefaultCondition(io::Printer* printer,
} else if (field->cpp_type() == FieldDescriptor::CPPTYPE_MESSAGE) {
// Message fields still have has_$name$() methods.
format("if ($prefix$has_$name$()) {\n");
} else if (field->cpp_type() == FieldDescriptor::CPPTYPE_DOUBLE
|| field->cpp_type() == FieldDescriptor::CPPTYPE_FLOAT) {
// Handle float comparison to prevent -Wfloat-equal warnings
format("if (!($prefix$$name$() <= 0 && $prefix$$name$() >= 0)) {\n");
} else {
format("if ($prefix$$name$() != 0) {\n");
}