From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 1B6AF3858D3C; Tue, 28 Feb 2023 10:03:40 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 1B6AF3858D3C DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1677578620; bh=ilfgzZYWYiKR4vLQ1YKdlmXWQ/Mgjwx4tSJ2B0sl//I=; h=From:To:Subject:Date:From; b=oIFJZzOiJH5LFxZJpftjc4MVCjbDUMlkXjR2KYo8o2pLUstZq1JP/ARuoE26ScB+v fGsABouIwWqxV581ViRWfZmmzAm9qFzge0IJaQLANjaeo5bS6piHWvUsSxFBQosRJL v0F4pc+y6dSxqoC0y/P0PjsblaxTw5dKh0IFThgY= From: "chrisfriedt at gmail dot com" To: gcc-bugs@gcc.gnu.org Subject: [Bug c++/108965] New: g++: unable to parse c11 _Generics Date: Tue, 28 Feb 2023 10:03:39 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: c++ X-Bugzilla-Version: 11.3.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: chrisfriedt at gmail dot com X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Resolution: X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: bug_id short_desc product version bug_status bug_severity priority component assigned_to reporter target_milestone Message-ID: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 List-Id: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D108965 Bug ID: 108965 Summary: g++: unable to parse c11 _Generics Product: gcc Version: 11.3.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: chrisfriedt at gmail dot com Target Milestone: --- G++ version 11.3.0 fails to parse the C11 _Generic keyword. I would suspect that earlier versions also fail to do this and likely also that later versi= ons fail as well. gcc --version gcc (Ubuntu 11.3.0-1ubuntu1~22.04) 11.3.0 Copyright (C) 2021 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. It's not clear to me if any part of the ISO C++ standard requires a C++ compiler to parse C11 _Generic, but it certainly can make life less pleasan= t, as the equivalent C++ code can sometimes rely on static inline constexpr templates which are apparently "not cool" until C++14. This particularly affects people who are using somewhat older C++ toolchains that do not yet support C++14. LLVM has no problem, OTOH. Sample taken from https://en.cppreference.com/w/c/language/generic ``` #include #include // Possible implementation of the tgmath.h macro cbrt #define cbrt(X) _Generic((X), \ long double: cbrtl, \ default: cbrt, \ float: cbrtf \ )(X) int main(void) { double x =3D 8.0; const float y =3D 3.375; printf("cbrt(8.0) =3D %f\n", cbrt(x)); // selects the default cbrt printf("cbrtf(3.375) =3D %f\n", cbrt(y)); // converts const float to fl= oat, // then selects cbrtf } ``` ``` g++ -o /tmp/main /tmp/main.cpp /tmp/main.cpp: In function =E2=80=98int main()=E2=80=99: /tmp/main.cpp:6:15: error: expected primary-expression before =E2=80=98long= =E2=80=99 6 | long double: cbrtl, \ | ^~~~ /tmp/main.cpp:15:32: note: in expansion of macro =E2=80=98cbrt=E2=80=99 15 | printf("cbrt(8.0) =3D %f\n", cbrt(x)); // selects the default c= brt | ^~~~ /tmp/main.cpp:7:19: error: expected primary-expression before =E2=80=98defa= ult=E2=80=99 7 | default: cbrt, \ | ^~~~~~~ /tmp/main.cpp:15:32: note: in expansion of macro =E2=80=98cbrt=E2=80=99 15 | printf("cbrt(8.0) =3D %f\n", cbrt(x)); // selects the default c= brt | ^~~~ /tmp/main.cpp:8:21: error: expected primary-expression before =E2=80=98floa= t=E2=80=99 8 | float: cbrtf \ | ^~~~~ /tmp/main.cpp:15:32: note: in expansion of macro =E2=80=98cbrt=E2=80=99 15 | printf("cbrt(8.0) =3D %f\n", cbrt(x)); // selects the default c= brt | ^~~~ /tmp/main.cpp:5:17: error: =E2=80=98_Generic=E2=80=99 was not declared in t= his scope 5 | #define cbrt(X) _Generic((X), \ | ^~~~~~~~ /tmp/main.cpp:15:32: note: in expansion of macro =E2=80=98cbrt=E2=80=99 15 | printf("cbrt(8.0) =3D %f\n", cbrt(x)); // selects the default c= brt | ^~~~ /tmp/main.cpp:6:15: error: expected primary-expression before =E2=80=98long= =E2=80=99 6 | long double: cbrtl, \ | ^~~~ /tmp/main.cpp:16:35: note: in expansion of macro =E2=80=98cbrt=E2=80=99 16 | printf("cbrtf(3.375) =3D %f\n", cbrt(y)); // converts const flo= at to float, | ^~~~ /tmp/main.cpp:7:19: error: expected primary-expression before =E2=80=98defa= ult=E2=80=99 7 | default: cbrt, \ | ^~~~~~~ /tmp/main.cpp:16:35: note: in expansion of macro =E2=80=98cbrt=E2=80=99 16 | printf("cbrtf(3.375) =3D %f\n", cbrt(y)); // converts const flo= at to float, | ^~~~ /tmp/main.cpp:8:21: error: expected primary-expression before =E2=80=98floa= t=E2=80=99 8 | float: cbrtf \ | ^~~~~ /tmp/main.cpp:16:35: note: in expansion of macro =E2=80=98cbrt=E2=80=99 16 | printf("cbrtf(3.375) =3D %f\n", cbrt(y)); // converts const flo= at to float, | ^~~~ ```=