public inbox for gcc-bugs@sourceware.org help / color / mirror / Atom feed
From: "chrisfriedt at gmail dot com" <gcc-bugzilla@gcc.gnu.org> 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 [thread overview] Message-ID: <bug-108965-4@http.gcc.gnu.org/bugzilla/> (raw) https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108965 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 versions 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 pleasant, 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 <stdio.h> #include <math.h> // 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 = 8.0; const float y = 3.375; printf("cbrt(8.0) = %f\n", cbrt(x)); // selects the default cbrt printf("cbrtf(3.375) = %f\n", cbrt(y)); // converts const float to float, // then selects cbrtf } ``` ``` g++ -o /tmp/main /tmp/main.cpp /tmp/main.cpp: In function ‘int main()’: /tmp/main.cpp:6:15: error: expected primary-expression before ‘long’ 6 | long double: cbrtl, \ | ^~~~ /tmp/main.cpp:15:32: note: in expansion of macro ‘cbrt’ 15 | printf("cbrt(8.0) = %f\n", cbrt(x)); // selects the default cbrt | ^~~~ /tmp/main.cpp:7:19: error: expected primary-expression before ‘default’ 7 | default: cbrt, \ | ^~~~~~~ /tmp/main.cpp:15:32: note: in expansion of macro ‘cbrt’ 15 | printf("cbrt(8.0) = %f\n", cbrt(x)); // selects the default cbrt | ^~~~ /tmp/main.cpp:8:21: error: expected primary-expression before ‘float’ 8 | float: cbrtf \ | ^~~~~ /tmp/main.cpp:15:32: note: in expansion of macro ‘cbrt’ 15 | printf("cbrt(8.0) = %f\n", cbrt(x)); // selects the default cbrt | ^~~~ /tmp/main.cpp:5:17: error: ‘_Generic’ was not declared in this scope 5 | #define cbrt(X) _Generic((X), \ | ^~~~~~~~ /tmp/main.cpp:15:32: note: in expansion of macro ‘cbrt’ 15 | printf("cbrt(8.0) = %f\n", cbrt(x)); // selects the default cbrt | ^~~~ /tmp/main.cpp:6:15: error: expected primary-expression before ‘long’ 6 | long double: cbrtl, \ | ^~~~ /tmp/main.cpp:16:35: note: in expansion of macro ‘cbrt’ 16 | printf("cbrtf(3.375) = %f\n", cbrt(y)); // converts const float to float, | ^~~~ /tmp/main.cpp:7:19: error: expected primary-expression before ‘default’ 7 | default: cbrt, \ | ^~~~~~~ /tmp/main.cpp:16:35: note: in expansion of macro ‘cbrt’ 16 | printf("cbrtf(3.375) = %f\n", cbrt(y)); // converts const float to float, | ^~~~ /tmp/main.cpp:8:21: error: expected primary-expression before ‘float’ 8 | float: cbrtf \ | ^~~~~ /tmp/main.cpp:16:35: note: in expansion of macro ‘cbrt’ 16 | printf("cbrtf(3.375) = %f\n", cbrt(y)); // converts const float to float, | ^~~~ ```
next reply other threads:[~2023-02-28 10:03 UTC|newest] Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top 2023-02-28 10:03 chrisfriedt at gmail dot com [this message] 2023-02-28 10:20 ` [Bug c++/108965] " redi at gcc dot gnu.org 2023-02-28 10:35 ` redi at gcc dot gnu.org 2023-02-28 10:54 ` chrisfriedt at gmail dot com 2023-02-28 11:02 ` pinskia at gcc dot gnu.org 2023-02-28 11:50 ` redi at gcc dot gnu.org 2023-02-28 12:28 ` chrisfriedt at gmail dot com 2023-02-28 12:37 ` redi at gcc dot gnu.org 2023-02-28 12:40 ` chrisfriedt at gmail dot com 2023-02-28 12:48 ` redi at gcc dot gnu.org 2023-02-28 12:58 ` chrisfriedt at gmail dot com 2023-02-28 13:34 ` chrisfriedt at gmail dot com
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=bug-108965-4@http.gcc.gnu.org/bugzilla/ \ --to=gcc-bugzilla@gcc.gnu.org \ --cc=gcc-bugs@gcc.gnu.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).