HomeFreeBSD

include/math.h: fix warning with -Wconversion

Description

include/math.h: fix warning with -Wconversion

The way the __fp_type_select macro uses the _Generic expression causes
gcc to throw a warning on valid code if the -Wconversion flag is used.

For example, consider the following program:

#include <math.h>
int main()
{
	double x = 1.0;
	isnan(x);
	return 0;
}

which throws a warning:

$ gcc -Wconversion a.c
a.c:5:15: warning: conversion from 'double' to 'float' may change value [-Wfloat-conversion]
    5 |         isnan(x);
      |               ^

This happens because the functions are invoked inside of the _Generic.
Looking at the example of _Generic in the C11 specification, one sees
that the parameters are outside of the _Generic expression (see page 79
here: https://www.open-std.org/jtc1/sc22/wg14/www/docs/n1570.pdf).

Reference: https://stackoverflow.com/a/68309379
Signed-off-by: Martin Oliveira <martin.oliveira@eideticom.com>
Reviewed by: imp
Pull Request: https://github.com/freebsd/freebsd-src/pull/841

Details

Provenance
Martin Oliveira <martin.oliveira@eideticom.com>Authored on Sep 12 2023, 8:31 PM
impCommitted on Feb 3 2024, 4:05 AM
Parents
rGef35e5eaee9c: release: Add the Ed25519 vagrant insecure key
Branches
Unknown
Tags
Unknown

Event Timeline

imp committed rG4309f9f2347e: include/math.h: fix warning with -Wconversion (authored by Martin Oliveira <martin.oliveira@eideticom.com>).Feb 3 2024, 4:05 AM