Bug 254714 - include <math.h> contains a c11 extension
Summary: include <math.h> contains a c11 extension
Status: Closed FIXED
Alias: None
Product: Base System
Classification: Unclassified
Component: misc (show other bugs)
Version: 12.2-STABLE
Hardware: Any Any
: --- Affects Only Me
Assignee: freebsd-bugs (Nobody)
URL: https://github.com/igraph/igraph/issu...
Keywords:
Depends on:
Blocks:
 
Reported: 2021-04-02 09:21 UTC by Yuri Victorovich
Modified: 2022-10-25 23:40 UTC (History)
1 user (show)

See Also:
dim: mfc-stable13+
dim: mfc-stable12+
dim: mfc-stable11+


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Yuri Victorovich freebsd_committer freebsd_triage 2021-04-02 09:21:45 UTC
This code:
> #include <math.h>
> 
> int main() { return !isfinite(1.0); }

triggers this warning:
> $ cc -Wall -Wextra -pedantic -std=gnu99 -c  x.c 
> x.c:4:22: warning: '_Generic' is a C11 extension [-Wc11-extensions]
> int main() { return !isfinite(1.0); }
>                      ^
> /usr/include/math.h:111:21: note: expanded from macro 'isfinite'
> #define isfinite(x) __fp_type_select(x, __isfinitef, __isfinite, __isfinitel)
>                     ^
> /usr/include/math.h:82:39: note: expanded from macro '__fp_type_select'
> #define __fp_type_select(x, f, d, ld) _Generic((x),                     \
>                                       ^
> 1 warning generated.

The igraph project used -Werror and this problem caused build failure.
Comment 1 Yuri Victorovich freebsd_committer freebsd_triage 2021-04-08 08:17:46 UTC
Other packages are also affected: https://www.google.com/search?q=%22%27_Generic%27+is+a+C11+extension%22+freebsd
Comment 2 Dimitry Andric freebsd_committer freebsd_triage 2021-04-08 10:06:53 UTC
Why is this code trying to compile with -pedantic? If you use that, you know that you will receive pedantic warnings, which are not usually useful. I'd say the solution is "do not use -pedantic"? Then it works just fine.
Comment 3 Yuri Victorovich freebsd_committer freebsd_triage 2021-04-08 10:11:37 UTC
(In reply to Dimitry Andric from comment #2)

Is appears that many projects turn on -pedantic and get this warning which is converted to error with -Werror. Example is igraph project: https://github.com/igraph/igraph/issues/1748
Comment 4 commit-hook freebsd_committer freebsd_triage 2021-04-08 16:33:02 UTC
A commit in branch main references this bug:

URL: https://cgit.FreeBSD.org/src/commit/?id=7702d940ec9a27fd4ab9e3991fc582b369b5eedc

commit 7702d940ec9a27fd4ab9e3991fc582b369b5eedc
Author:     Dimitry Andric <dim@FreeBSD.org>
AuthorDate: 2021-04-08 11:13:15 +0000
Commit:     Dimitry Andric <dim@FreeBSD.org>
CommitDate: 2021-04-08 16:20:32 +0000

    Avoid -pedantic warnings about using _Generic in __fp_type_select

    When compiling parts of math.h with clang using a C standard before C11,
    and using -pedantic, it will result in warnings similar to:

    bug254714.c:5:11: warning: '_Generic' is a C11 extension [-Wc11-extensions]
      return !isfinite(1.0);
              ^
    /usr/include/math.h:111:21: note: expanded from macro 'isfinite'
                        ^
    /usr/include/math.h:82:39: note: expanded from macro '__fp_type_select'
                                          ^

    This is because the block that enables use of _Generic is conditional
    not only on C11, but also on whether the compiler advertises support for
    C generic selections via __has_extension(c_generic_selections).

    To work around the warning without having to pessimize the code, use the
    __extension__ keyword, which is supported by both clang and gcc. While
    here, remove the check for __clang__, as _Generic has been supported for
    a long time by gcc too now.

    Reported by:    yuri
    PR:             254714
    MFC after:      1 week

 lib/msun/src/math.h | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)
Comment 5 commit-hook freebsd_committer freebsd_triage 2021-04-15 17:26:10 UTC
A commit in branch stable/13 references this bug:

URL: https://cgit.FreeBSD.org/src/commit/?id=7abb639572d847d4c5ff134f4441cb39447b3c9c

commit 7abb639572d847d4c5ff134f4441cb39447b3c9c
Author:     Dimitry Andric <dim@FreeBSD.org>
AuthorDate: 2021-04-08 11:13:15 +0000
Commit:     Dimitry Andric <dim@FreeBSD.org>
CommitDate: 2021-04-15 16:51:08 +0000

    Avoid -pedantic warnings about using _Generic in __fp_type_select

    When compiling parts of math.h with clang using a C standard before C11,
    and using -pedantic, it will result in warnings similar to:

    bug254714.c:5:11: warning: '_Generic' is a C11 extension [-Wc11-extensions]
      return !isfinite(1.0);
              ^
    /usr/include/math.h:111:21: note: expanded from macro 'isfinite'
                        ^
    /usr/include/math.h:82:39: note: expanded from macro '__fp_type_select'
                                          ^

    This is because the block that enables use of _Generic is conditional
    not only on C11, but also on whether the compiler advertises support for
    C generic selections via __has_extension(c_generic_selections).

    To work around the warning without having to pessimize the code, use the
    __extension__ keyword, which is supported by both clang and gcc. While
    here, remove the check for __clang__, as _Generic has been supported for
    a long time by gcc too now.

    Reported by:    yuri
    PR:             254714

 lib/msun/src/math.h | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)
Comment 6 commit-hook freebsd_committer freebsd_triage 2021-04-15 17:26:11 UTC
A commit in branch stable/12 references this bug:

URL: https://cgit.FreeBSD.org/src/commit/?id=81c5f1451c4e2221413a9b05aadcfd74a1182848

commit 81c5f1451c4e2221413a9b05aadcfd74a1182848
Author:     Dimitry Andric <dim@FreeBSD.org>
AuthorDate: 2021-04-08 11:13:15 +0000
Commit:     Dimitry Andric <dim@FreeBSD.org>
CommitDate: 2021-04-15 16:50:56 +0000

    Avoid -pedantic warnings about using _Generic in __fp_type_select

    When compiling parts of math.h with clang using a C standard before C11,
    and using -pedantic, it will result in warnings similar to:

    bug254714.c:5:11: warning: '_Generic' is a C11 extension [-Wc11-extensions]
      return !isfinite(1.0);
              ^
    /usr/include/math.h:111:21: note: expanded from macro 'isfinite'
                        ^
    /usr/include/math.h:82:39: note: expanded from macro '__fp_type_select'
                                          ^

    This is because the block that enables use of _Generic is conditional
    not only on C11, but also on whether the compiler advertises support for
    C generic selections via __has_extension(c_generic_selections).

    To work around the warning without having to pessimize the code, use the
    __extension__ keyword, which is supported by both clang and gcc. While
    here, remove the check for __clang__, as _Generic has been supported for
    a long time by gcc too now.

    Reported by:    yuri
    PR:             254714

 lib/msun/src/math.h | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)
Comment 7 commit-hook freebsd_committer freebsd_triage 2021-04-15 17:27:12 UTC
A commit in branch stable/11 references this bug:

URL: https://cgit.FreeBSD.org/src/commit/?id=b582d1422b4db6c22ff061a32257a83405d06cc9

commit b582d1422b4db6c22ff061a32257a83405d06cc9
Author:     Dimitry Andric <dim@FreeBSD.org>
AuthorDate: 2021-04-08 11:13:15 +0000
Commit:     Dimitry Andric <dim@FreeBSD.org>
CommitDate: 2021-04-15 10:24:28 +0000

    Avoid -pedantic warnings about using _Generic in __fp_type_select

    When compiling parts of math.h with clang using a C standard before C11,
    and using -pedantic, it will result in warnings similar to:

    bug254714.c:5:11: warning: '_Generic' is a C11 extension [-Wc11-extensions]
      return !isfinite(1.0);
              ^
    /usr/include/math.h:111:21: note: expanded from macro 'isfinite'
                        ^
    /usr/include/math.h:82:39: note: expanded from macro '__fp_type_select'
                                          ^

    This is because the block that enables use of _Generic is conditional
    not only on C11, but also on whether the compiler advertises support for
    C generic selections via __has_extension(c_generic_selections).

    To work around the warning without having to pessimize the code, use the
    __extension__ keyword, which is supported by both clang and gcc. While
    here, remove the check for __clang__, as _Generic has been supported for
    a long time by gcc too now.

    Reported by:    yuri
    PR:             254714

 lib/msun/src/math.h | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)
Comment 8 commit-hook freebsd_committer freebsd_triage 2021-04-15 17:28:15 UTC
A commit in branch stable/10 references this bug:

URL: https://cgit.FreeBSD.org/src/commit/?id=74b123c0a5ecfe2081c47de98820cdfabb64024d

commit 74b123c0a5ecfe2081c47de98820cdfabb64024d
Author:     Dimitry Andric <dim@FreeBSD.org>
AuthorDate: 2021-04-08 11:13:15 +0000
Commit:     Dimitry Andric <dim@FreeBSD.org>
CommitDate: 2021-04-15 10:26:48 +0000

    Avoid -pedantic warnings about using _Generic in __fp_type_select

    When compiling parts of math.h with clang using a C standard before C11,
    and using -pedantic, it will result in warnings similar to:

    bug254714.c:5:11: warning: '_Generic' is a C11 extension [-Wc11-extensions]
      return !isfinite(1.0);
              ^
    /usr/include/math.h:111:21: note: expanded from macro 'isfinite'
                        ^
    /usr/include/math.h:82:39: note: expanded from macro '__fp_type_select'
                                          ^

    This is because the block that enables use of _Generic is conditional
    not only on C11, but also on whether the compiler advertises support for
    C generic selections via __has_extension(c_generic_selections).

    To work around the warning without having to pessimize the code, use the
    __extension__ keyword, which is supported by both clang and gcc. While
    here, remove the check for __clang__, as _Generic has been supported for
    a long time by gcc too now.

    Reported by:    yuri
    PR:             254714

 lib/msun/src/math.h | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)