Skip to content

Warning from Visual Studio 19 regarding unsafe use of bool #814

@bjornblissing

Description

@bjornblissing

The following section spawns a C4804 warning when the template type T is bool:

geometry_attribute.h(290,13): warning C4804: '<': unsafe use of type 'bool' in operation
geometry_attribute.h(290,35): warning C4804: '>': unsafe use of type 'bool' in operation

if (std::is_integral<T>::value && std::is_integral<OutT>::value) {
static constexpr OutT kOutMin =
std::is_signed<T>::value ? std::numeric_limits<OutT>::lowest() : 0;
if (in_value < kOutMin || in_value > std::numeric_limits<OutT>::max()) {
return false;
}
}

This warning can be avoided by skipping the check when type T is bool. This check can be skipped safely since we are guaranteed that bool will fit in the output type OutT, given that OutT is an integral type.

Suggested change on Line 287:

if (!std::is_same<T, bool>::value && std::is_integral<T>::value && std::is_integral<OutT>::value) {

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions