No bool implicit warning for floating type?

This snippet seems to compile in clang without warning, even with -Weverything:

double x;
...
if (fabs(x > 1.0)) {
   ...
}

Am I missing something? Or does the compiler and C ++ standard think that a value other than boolto doublemakes sense?

+4
source share
1 answer

This is a consequence of the creation of an integral type bool. According to the C ++ standard, section 3.9.1.6

bool true, false (: signed, unsigned, short long bool signed bool) - ) bool . ( )

, bool float , int, , 4.5.6:

bool prvalue int, false , true .

: ++ 11 fabs , bool int , fabs .

+6

Source: https://habr.com/ru/post/1542062/


All Articles