* [PATCH] gdbsupport/gdb_proc_service.h: use decltype instead of typeof
@ 2021-09-20 1:06 Simon Marchi
2021-09-20 9:48 ` Andrew Burgess
0 siblings, 1 reply; 5+ messages in thread
From: Simon Marchi @ 2021-09-20 1:06 UTC (permalink / raw)
To: gdb-patches; +Cc: liulk, Simon Marchi
Bug 28341 shows that GDB fails to compile when built with -std=c++11.
I don't know much about the use case, but according to the author of the
bug:
I encountered the scenario where CXX is set to "g++ -std=c++11" when
I try to compile binutils under GCC as part of the GCC 3-stage
compilation, which is common for building a cross-compiler.
The author of the bug suggests using __typeof__ instead of typeof. But
since we're using C++, we might as well use decltype, which is standard.
This is what this patch does.
The failure (and fix) can be observed by configuring GDB with CXX="g++
-std=c++11":
CXX linux-low.o
In file included from /home/simark/src/binutils-gdb/gdbserver/gdb_proc_service.h:22,
from /home/simark/src/binutils-gdb/gdbserver/linux-low.h:27,
from /home/simark/src/binutils-gdb/gdbserver/linux-low.cc:20:
/home/simark/src/binutils-gdb/gdbserver/../gdbsupport/gdb_proc_service.h:177:50: error: expected constructor, destructor, or type conversion before ‘(’ token
177 | __attribute__((visibility ("default"))) typeof (SYM) SYM
| ^
/home/simark/src/binutils-gdb/gdbserver/../gdbsupport/gdb_proc_service.h:179:1: note: in expansion of macro ‘PS_EXPORT’
179 | PS_EXPORT (ps_get_thread_area);
| ^~~~~~~~~
Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=28341
Change-Id: I84fbaae938209d8d935ca08dec9b7e6a0dd1bda0
---
gdbsupport/gdb_proc_service.h | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/gdbsupport/gdb_proc_service.h b/gdbsupport/gdb_proc_service.h
index db169acc8c28..1131a40f7d04 100644
--- a/gdbsupport/gdb_proc_service.h
+++ b/gdbsupport/gdb_proc_service.h
@@ -174,7 +174,7 @@ EXTERN_C_POP
-fvisibility=hidden. */
#define PS_EXPORT(SYM) \
- __attribute__((visibility ("default"))) typeof (SYM) SYM
+ __attribute__((visibility ("default"))) decltype (SYM) SYM
PS_EXPORT (ps_get_thread_area);
PS_EXPORT (ps_getpid);
--
2.33.0
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] gdbsupport/gdb_proc_service.h: use decltype instead of typeof
2021-09-20 1:06 [PATCH] gdbsupport/gdb_proc_service.h: use decltype instead of typeof Simon Marchi
@ 2021-09-20 9:48 ` Andrew Burgess
2021-09-20 12:01 ` Simon Marchi
0 siblings, 1 reply; 5+ messages in thread
From: Andrew Burgess @ 2021-09-20 9:48 UTC (permalink / raw)
To: Simon Marchi; +Cc: gdb-patches, liulk
* Simon Marchi via Gdb-patches <gdb-patches@sourceware.org> [2021-09-19 21:06:10 -0400]:
> Bug 28341 shows that GDB fails to compile when built with -std=c++11.
> I don't know much about the use case, but according to the author of the
> bug:
>
> I encountered the scenario where CXX is set to "g++ -std=c++11" when
> I try to compile binutils under GCC as part of the GCC 3-stage
> compilation, which is common for building a cross-compiler.
>
> The author of the bug suggests using __typeof__ instead of typeof. But
> since we're using C++, we might as well use decltype, which is standard.
> This is what this patch does.
This change makes sense to me.
Thanks,
Andrew
>
> The failure (and fix) can be observed by configuring GDB with CXX="g++
> -std=c++11":
>
> CXX linux-low.o
> In file included from /home/simark/src/binutils-gdb/gdbserver/gdb_proc_service.h:22,
> from /home/simark/src/binutils-gdb/gdbserver/linux-low.h:27,
> from /home/simark/src/binutils-gdb/gdbserver/linux-low.cc:20:
> /home/simark/src/binutils-gdb/gdbserver/../gdbsupport/gdb_proc_service.h:177:50: error: expected constructor, destructor, or type conversion before ‘(’ token
> 177 | __attribute__((visibility ("default"))) typeof (SYM) SYM
> | ^
> /home/simark/src/binutils-gdb/gdbserver/../gdbsupport/gdb_proc_service.h:179:1: note: in expansion of macro ‘PS_EXPORT’
> 179 | PS_EXPORT (ps_get_thread_area);
> | ^~~~~~~~~
>
> Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=28341
> Change-Id: I84fbaae938209d8d935ca08dec9b7e6a0dd1bda0
> ---
> gdbsupport/gdb_proc_service.h | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/gdbsupport/gdb_proc_service.h b/gdbsupport/gdb_proc_service.h
> index db169acc8c28..1131a40f7d04 100644
> --- a/gdbsupport/gdb_proc_service.h
> +++ b/gdbsupport/gdb_proc_service.h
> @@ -174,7 +174,7 @@ EXTERN_C_POP
> -fvisibility=hidden. */
>
> #define PS_EXPORT(SYM) \
> - __attribute__((visibility ("default"))) typeof (SYM) SYM
> + __attribute__((visibility ("default"))) decltype (SYM) SYM
>
> PS_EXPORT (ps_get_thread_area);
> PS_EXPORT (ps_getpid);
> --
> 2.33.0
>
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] gdbsupport/gdb_proc_service.h: use decltype instead of typeof
2021-09-20 9:48 ` Andrew Burgess
@ 2021-09-20 12:01 ` Simon Marchi
2021-09-20 12:30 ` Pedro Alves
0 siblings, 1 reply; 5+ messages in thread
From: Simon Marchi @ 2021-09-20 12:01 UTC (permalink / raw)
To: Andrew Burgess; +Cc: gdb-patches, liulk
On 2021-09-20 5:48 a.m., Andrew Burgess wrote:
> * Simon Marchi via Gdb-patches <gdb-patches@sourceware.org> [2021-09-19 21:06:10 -0400]:
>
>> Bug 28341 shows that GDB fails to compile when built with -std=c++11.
>> I don't know much about the use case, but according to the author of the
>> bug:
>>
>> I encountered the scenario where CXX is set to "g++ -std=c++11" when
>> I try to compile binutils under GCC as part of the GCC 3-stage
>> compilation, which is common for building a cross-compiler.
>>
>> The author of the bug suggests using __typeof__ instead of typeof. But
>> since we're using C++, we might as well use decltype, which is standard.
>> This is what this patch does.
>
> This change makes sense to me.
Thanks, pushed.
For the record, I looked into using the "noext" keyword of the
AX_CXX_COMPILE_STDCXX macro, to make it so we would always build GDB
with -std=c++XX (to avoid GNU extensions). However, that would make it
so it would always use -std=c++11, even if the compiler defaults to a
more recent C++. It would be a behavior change compared to what we do
today, where if the compiler defaults to a more recent C++, we leave it
at that.
Simon
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] gdbsupport/gdb_proc_service.h: use decltype instead of typeof
2021-09-20 12:01 ` Simon Marchi
@ 2021-09-20 12:30 ` Pedro Alves
2021-09-20 12:33 ` Simon Marchi
0 siblings, 1 reply; 5+ messages in thread
From: Pedro Alves @ 2021-09-20 12:30 UTC (permalink / raw)
To: Simon Marchi, Andrew Burgess; +Cc: liulk, gdb-patches
On 2021-09-20 1:01 p.m., Simon Marchi via Gdb-patches wrote:
> For the record, I looked into using the "noext" keyword of the
> AX_CXX_COMPILE_STDCXX macro, to make it so we would always build GDB
> with -std=c++XX (to avoid GNU extensions). However, that would make it
> so it would always use -std=c++11, even if the compiler defaults to a
> more recent C++. It would be a behavior change compared to what we do
> today, where if the compiler defaults to a more recent C++, we leave it
> at that.
>
FWIW, I'd object to that. I don't think we want to _disable_ GNU extensions.
There's nothing evil about them. Just not rely on them if unnecessary. If some GNU
extension is available that e.g., makes code faster, I see no reason to prohibit using it,
as long as guarded with some #ifdef check or some such and a fallback.
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] gdbsupport/gdb_proc_service.h: use decltype instead of typeof
2021-09-20 12:30 ` Pedro Alves
@ 2021-09-20 12:33 ` Simon Marchi
0 siblings, 0 replies; 5+ messages in thread
From: Simon Marchi @ 2021-09-20 12:33 UTC (permalink / raw)
To: Pedro Alves, Andrew Burgess; +Cc: liulk, gdb-patches
On 2021-09-20 8:30 a.m., Pedro Alves wrote:
> On 2021-09-20 1:01 p.m., Simon Marchi via Gdb-patches wrote:
>
>> For the record, I looked into using the "noext" keyword of the
>> AX_CXX_COMPILE_STDCXX macro, to make it so we would always build GDB
>> with -std=c++XX (to avoid GNU extensions). However, that would make it
>> so it would always use -std=c++11, even if the compiler defaults to a
>> more recent C++. It would be a behavior change compared to what we do
>> today, where if the compiler defaults to a more recent C++, we leave it
>> at that.
>>
>
> FWIW, I'd object to that. I don't think we want to _disable_ GNU extensions.
> There's nothing evil about them. Just not rely on them if unnecessary. If some GNU
> extension is available that e.g., makes code faster, I see no reason to prohibit using it,
> as long as guarded with some #ifdef check or some such and a fallback.
Ok, I saw it as a binary choice, use extensions or don't use extensions,
but it's true we can have two implementations guarded by ifdefs. Using
-std=c++XX would be another axis of configuration for an hypothetical CI
to test, to make sure that both branches of the ifdefs build.
Simon
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2021-09-20 12:33 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-09-20 1:06 [PATCH] gdbsupport/gdb_proc_service.h: use decltype instead of typeof Simon Marchi
2021-09-20 9:48 ` Andrew Burgess
2021-09-20 12:01 ` Simon Marchi
2021-09-20 12:30 ` Pedro Alves
2021-09-20 12:33 ` Simon Marchi
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).