public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/108965] New: g++: unable to parse c11 _Generics
@ 2023-02-28 10:03 chrisfriedt at gmail dot com
2023-02-28 10:20 ` [Bug c++/108965] " redi at gcc dot gnu.org
` (10 more replies)
0 siblings, 11 replies; 12+ messages in thread
From: chrisfriedt at gmail dot com @ 2023-02-28 10:03 UTC (permalink / raw)
To: gcc-bugs
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,
| ^~~~
```
^ permalink raw reply [flat|nested] 12+ messages in thread
* [Bug c++/108965] g++: unable to parse c11 _Generics
2023-02-28 10:03 [Bug c++/108965] New: g++: unable to parse c11 _Generics chrisfriedt at gmail dot com
@ 2023-02-28 10:20 ` redi at gcc dot gnu.org
2023-02-28 10:35 ` redi at gcc dot gnu.org
` (9 subsequent siblings)
10 siblings, 0 replies; 12+ messages in thread
From: redi at gcc dot gnu.org @ 2023-02-28 10:20 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108965
--- Comment #1 from Jonathan Wakely <redi at gcc dot gnu.org> ---
(In reply to Christopher Friedt from comment #0)
> It's not clear to me if any part of the ISO C++ standard requires a C++
> compiler to parse C11 _Generic,
It's very clear that it doesn't, _Generic is never mentioned anywhere in the
C++ standard.
> 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
Why not? What exactly is the equivalent code you're referring to?
C++ has never needed _Generic because it supports function overloading.
^ permalink raw reply [flat|nested] 12+ messages in thread
* [Bug c++/108965] g++: unable to parse c11 _Generics
2023-02-28 10:03 [Bug c++/108965] New: g++: unable to parse c11 _Generics chrisfriedt at gmail dot com
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
` (8 subsequent siblings)
10 siblings, 0 replies; 12+ messages in thread
From: redi at gcc dot gnu.org @ 2023-02-28 10:35 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108965
Jonathan Wakely <redi at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|UNCONFIRMED |RESOLVED
Resolution|--- |INVALID
--- Comment #2 from Jonathan Wakely <redi at gcc dot gnu.org> ---
I've commented on the github issue. There is no G++ bug here.
^ permalink raw reply [flat|nested] 12+ messages in thread
* [Bug c++/108965] g++: unable to parse c11 _Generics
2023-02-28 10:03 [Bug c++/108965] New: g++: unable to parse c11 _Generics chrisfriedt at gmail dot com
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
` (7 subsequent siblings)
10 siblings, 0 replies; 12+ messages in thread
From: chrisfriedt at gmail dot com @ 2023-02-28 10:54 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108965
--- Comment #3 from Christopher Friedt <chrisfriedt at gmail dot com> ---
All you need to do is look at the example above pulled directly from
cppreference.com, but please simply gaslight the user if that's an easier path
to resolution for you.
^ permalink raw reply [flat|nested] 12+ messages in thread
* [Bug c++/108965] g++: unable to parse c11 _Generics
2023-02-28 10:03 [Bug c++/108965] New: g++: unable to parse c11 _Generics chrisfriedt at gmail dot com
` (2 preceding siblings ...)
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
` (6 subsequent siblings)
10 siblings, 0 replies; 12+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-02-28 11:02 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108965
--- Comment #4 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
(In reply to Christopher Friedt from comment #3)
> All you need to do is look at the example above pulled directly from
> cppreference.com, but please simply gaslight the user if that's an easier
> path to resolution for you.
There is no gaslighting going on. In fact now you just being abusive for what
end?
The facts are:
The _Generic is only part of the C standard and not part of the C++ standard.
They are two different things.
Gcc's C++ frontend has never implemented _Generic support. GCC's C frontend
does though.
The C and C++ frontends in gcc do share some code but the parser has never been
shared.
^ permalink raw reply [flat|nested] 12+ messages in thread
* [Bug c++/108965] g++: unable to parse c11 _Generics
2023-02-28 10:03 [Bug c++/108965] New: g++: unable to parse c11 _Generics chrisfriedt at gmail dot com
` (3 preceding siblings ...)
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
` (5 subsequent siblings)
10 siblings, 0 replies; 12+ messages in thread
From: redi at gcc dot gnu.org @ 2023-02-28 11:50 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108965
--- Comment #5 from Jonathan Wakely <redi at gcc dot gnu.org> ---
(In reply to Christopher Friedt from comment #3)
> All you need to do is look at the example above pulled directly from
> cppreference.com, but please simply gaslight the user if that's an easier
> path to resolution for you.
WTF? How am I gaslighting you?
Your example is from cppreference.com/w/c/ which is the **C** reference. Look
at the breadcrumb thingy at the top of the page:
"C / C language / Expressions"
The C++ references are under cppreference.com/w/cpp/ instead of /w/c/
Go to https://en.cppreference.com/w/Main_Page and check that it has both C++
and C references on that site, with different URLs.
^ permalink raw reply [flat|nested] 12+ messages in thread
* [Bug c++/108965] g++: unable to parse c11 _Generics
2023-02-28 10:03 [Bug c++/108965] New: g++: unable to parse c11 _Generics chrisfriedt at gmail dot com
` (4 preceding siblings ...)
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
` (4 subsequent siblings)
10 siblings, 0 replies; 12+ messages in thread
From: chrisfriedt at gmail dot com @ 2023-02-28 12:28 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108965
--- Comment #6 from Christopher Friedt <chrisfriedt at gmail dot com> ---
It's supported OOTB in `clang++` but fails in `g++`.
The example above is the simplest example that illustrates the issue.
I am not being abusive, but it certainly did feel like gaslighting to read
"you're doing it wrong" / close invalid without any consideration.
Yes, the example is valid C. Yes, the example compiles under `clang++`. No, the
example does not compile under `g++`.
Thanks for following up! Although it's getting kind of condescending now.
^ permalink raw reply [flat|nested] 12+ messages in thread
* [Bug c++/108965] g++: unable to parse c11 _Generics
2023-02-28 10:03 [Bug c++/108965] New: g++: unable to parse c11 _Generics chrisfriedt at gmail dot com
` (5 preceding siblings ...)
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
` (3 subsequent siblings)
10 siblings, 0 replies; 12+ messages in thread
From: redi at gcc dot gnu.org @ 2023-02-28 12:37 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108965
--- Comment #7 from Jonathan Wakely <redi at gcc dot gnu.org> ---
(In reply to Christopher Friedt from comment #6)
> It's supported OOTB in `clang++` but fails in `g++`.
Nobody is disputing that, but Clang supports lots of things that aren't valid
in C++ and aren't supported by G++, and G++ supports things that aren't valid
in C++ and aren't supported by Clang. That's not a bug.
> The example above is the simplest example that illustrates the issue.
Yes, and it's not valid C++.
> I am not being abusive, but it certainly did feel like gaslighting to read
> "you're doing it wrong" / close invalid without any consideration.
I commented explaining that it's not in the C++ standard, and followed up in
the github issue where the real bug is. That's hardly "without consideration".
I've shown how to fix your C++ code to make it valid in C++11, and pointed out
a problem in your C code using _Generic. I didn't have to do any of that, and I
certainly won't bother doing so again.
^ permalink raw reply [flat|nested] 12+ messages in thread
* [Bug c++/108965] g++: unable to parse c11 _Generics
2023-02-28 10:03 [Bug c++/108965] New: g++: unable to parse c11 _Generics chrisfriedt at gmail dot com
` (6 preceding siblings ...)
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
` (2 subsequent siblings)
10 siblings, 0 replies; 12+ messages in thread
From: chrisfriedt at gmail dot com @ 2023-02-28 12:40 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108965
--- Comment #8 from Christopher Friedt <chrisfriedt at gmail dot com> ---
My code is clearly valid C++ according to g++ :-)
Thanks for your help in any case.
On Tue, Feb 28, 2023, 7:38 AM redi at gcc dot gnu.org <
gcc-bugzilla@gcc.gnu.org> wrote:
> https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108965
>
> --- Comment #7 from Jonathan Wakely <redi at gcc dot gnu.org> ---
> (In reply to Christopher Friedt from comment #6)
> > It's supported OOTB in `clang++` but fails in `g++`.
>
> Nobody is disputing that, but Clang supports lots of things that aren't
> valid
> in C++ and aren't supported by G++, and G++ supports things that aren't
> valid
> in C++ and aren't supported by Clang. That's not a bug.
>
> > The example above is the simplest example that illustrates the issue.
>
> Yes, and it's not valid C++.
>
> > I am not being abusive, but it certainly did feel like gaslighting to
> read
> > "you're doing it wrong" / close invalid without any consideration.
>
> I commented explaining that it's not in the C++ standard, and followed up
> in
> the github issue where the real bug is. That's hardly "without
> consideration".
> I've shown how to fix your C++ code to make it valid in C++11, and pointed
> out
> a problem in your C code using _Generic. I didn't have to do any of that,
> and I
> certainly won't bother doing so again.
>
> --
> You are receiving this mail because:
> You reported the bug.
^ permalink raw reply [flat|nested] 12+ messages in thread
* [Bug c++/108965] g++: unable to parse c11 _Generics
2023-02-28 10:03 [Bug c++/108965] New: g++: unable to parse c11 _Generics chrisfriedt at gmail dot com
` (7 preceding siblings ...)
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
10 siblings, 0 replies; 12+ messages in thread
From: redi at gcc dot gnu.org @ 2023-02-28 12:48 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108965
--- Comment #9 from Jonathan Wakely <redi at gcc dot gnu.org> ---
(In reply to Christopher Friedt from comment #8)
> My code is clearly valid C++ according to g++ :-)
Maybe you mean clang++ but even then, no it's not:
$ clang++ -pedantic gen.cc
gen.cc:15:32: warning: '_Generic' is a C11 extension [-Wc11-extensions]
printf("cbrt(8.0) = %f\n", cbrt(x)); // selects the default cbrt
^
gen.cc:5:17: note: expanded from macro 'cbrt'
#define cbrt(X) _Generic((X), \
^
gen.cc:16:35: warning: '_Generic' is a C11 extension [-Wc11-extensions]
printf("cbrtf(3.375) = %f\n", cbrt(y)); // converts const float to float,
^
gen.cc:5:17: note: expanded from macro 'cbrt'
#define cbrt(X) _Generic((X), \
^
2 warnings generated.
It's a non-standard extension, not valid C++.
^ permalink raw reply [flat|nested] 12+ messages in thread
* [Bug c++/108965] g++: unable to parse c11 _Generics
2023-02-28 10:03 [Bug c++/108965] New: g++: unable to parse c11 _Generics chrisfriedt at gmail dot com
` (8 preceding siblings ...)
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
10 siblings, 0 replies; 12+ messages in thread
From: chrisfriedt at gmail dot com @ 2023-02-28 12:58 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108965
--- Comment #10 from Christopher Friedt <chrisfriedt at gmail dot com> ---
Thanks - I wasn't using -pedantic, but you have certainly proven stuff.
^ permalink raw reply [flat|nested] 12+ messages in thread
* [Bug c++/108965] g++: unable to parse c11 _Generics
2023-02-28 10:03 [Bug c++/108965] New: g++: unable to parse c11 _Generics chrisfriedt at gmail dot com
` (9 preceding siblings ...)
2023-02-28 12:58 ` chrisfriedt at gmail dot com
@ 2023-02-28 13:34 ` chrisfriedt at gmail dot com
10 siblings, 0 replies; 12+ messages in thread
From: chrisfriedt at gmail dot com @ 2023-02-28 13:34 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108965
--- Comment #11 from Christopher Friedt <chrisfriedt at gmail dot com> ---
(In reply to Jonathan Wakely from comment #9)
> (In reply to Christopher Friedt from comment #8)
> > My code is clearly valid C++ according to g++ :-)
>
> Maybe you mean clang++ but even then, no it's not:
I was talking about the code at the linked PR. It's valid C++11 according to
g++ (and clang++).
I was not talking about the cppreference.com example (which is not my code,
which is what you seem to be referencing as my code).
I did not compile the cppreference.com code with -pedantic, but if you feel you
need to in order to illustrate that you are right here, by all means.
I can also run a command that illustrates my point as well. See?
$ clang++ -std=c++11 -o /tmp/main /tmp/main.cpp
$ echo $?
0
So really, if you're trying to tell me that my observations did not actually
occur, that is, by definition, gaslighting.
> I commented explaining that it's not in the C++ standard, and followed up
> in the github issue where the real bug is.
The comments you made on the github pr do not highlight "where the real bug is"
because the code is not buggy - it produces the desired results.
> "I didn't have to do any of that, and I certainly won't bother doing so again"
Works for me!
^ permalink raw reply [flat|nested] 12+ messages in thread
end of thread, other threads:[~2023-02-28 13:34 UTC | newest]
Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-02-28 10:03 [Bug c++/108965] New: g++: unable to parse c11 _Generics chrisfriedt at gmail dot com
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
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).