* [libiberty] Add ARG_UNUSED as a C++-friendly replacement for ATTRIBUTE_UNUSED
@ 2004-07-11 23:52 Bernardo Innocenti
2004-07-12 4:20 ` Andrew Pinski
` (2 more replies)
0 siblings, 3 replies; 11+ messages in thread
From: Bernardo Innocenti @ 2004-07-11 23:52 UTC (permalink / raw)
To: GCC Patches, gdb-patches, binutils, Ian Lance Taylor, DJ Delorie
Hello,
this patch adds the ARG_UNUSED() macro to be used in place of
ATTRIBUTE_UNUSED. The syntax looks like this:
void foo (ARG_UNUSED (int, x))
{
}
The C++ frontend can't parse attribute((unused)) when it
appears after the variable name. The cleanest work-around
is using the standard C++ syntax to specify unused
parameters, which can also be used when bootstrapping from
other C++ compilers.
This patch is a prerequisite for the upcoming C++ bootstrap
patches that I've been preparing.
include/
2004-07-11 Bernardo Innocenti <bernie@develer.com>
* ansidecl.h (ARG_UNUSED): New Macro.
diff -u -p -r1.16 ansidecl.h
--- ansidecl.h 17 Jun 2003 14:10:00 -0000 1.16
+++ ansidecl.h 11 Jul 2004 15:38:23 -0000
@@ -312,4 +312,10 @@ So instead we use the macro below and te
#define __extension__
#endif
+#ifdef __cplusplus
+# define ARG_UNUSED(T, N) T
+#else
+# define ARG_UNUSED(T, N) T N ATTRIBUTE_UNUSED
+#endif
+
#endif /* ansidecl.h */
--
// Bernardo Innocenti - Develer S.r.l., R&D dept.
\X/ http://www.develer.com/
^ permalink raw reply [flat|nested] 11+ messages in thread* Re: [libiberty] Add ARG_UNUSED as a C++-friendly replacement for ATTRIBUTE_UNUSED
2004-07-11 23:52 [libiberty] Add ARG_UNUSED as a C++-friendly replacement for ATTRIBUTE_UNUSED Bernardo Innocenti
@ 2004-07-12 4:20 ` Andrew Pinski
2004-07-13 7:50 ` Bernardo Innocenti
2004-07-12 14:01 ` Andrew Cagney
2004-07-12 19:09 ` DJ Delorie
2 siblings, 1 reply; 11+ messages in thread
From: Andrew Pinski @ 2004-07-12 4:20 UTC (permalink / raw)
To: Bernardo Innocenti
Cc: GCC Patches, gdb-patches, binutils, Ian Lance Taylor, DJ Delorie
>
> Hello,
>
> this patch adds the ARG_UNUSED() macro to be used in place of
> ATTRIBUTE_UNUSED. The syntax looks like this:
>
> void foo (ARG_UNUSED (int, x))
> {
> }
>
> The C++ frontend can't parse attribute((unused)) when it
> appears after the variable name. The cleanest work-around
> is using the standard C++ syntax to specify unused
> parameters, which can also be used when bootstrapping from
> other C++ compilers.
>
> This patch is a prerequisite for the upcoming C++ bootstrap
> patches that I've been preparing.
Huh? Yes it can from 3.4.0 and above.
Thanks,
Andrew Pinski
who is just going through emails from the last two days
>
>
> include/
> 2004-07-11 Bernardo Innocenti <bernie@develer.com>
>
> * ansidecl.h (ARG_UNUSED): New Macro.
>
> diff -u -p -r1.16 ansidecl.h
> --- ansidecl.h 17 Jun 2003 14:10:00 -0000 1.16
> +++ ansidecl.h 11 Jul 2004 15:38:23 -0000
> @@ -312,4 +312,10 @@ So instead we use the macro below and te
> #define __extension__
> #endif
>
> +#ifdef __cplusplus
> +# define ARG_UNUSED(T, N) T
> +#else
> +# define ARG_UNUSED(T, N) T N ATTRIBUTE_UNUSED
> +#endif
> +
> #endif /* ansidecl.h */
>
> --
> // Bernardo Innocenti - Develer S.r.l., R&D dept.
> \X/ http://www.develer.com/
>
>
>
^ permalink raw reply [flat|nested] 11+ messages in thread* Re: [libiberty] Add ARG_UNUSED as a C++-friendly replacement for ATTRIBUTE_UNUSED
2004-07-12 4:20 ` Andrew Pinski
@ 2004-07-13 7:50 ` Bernardo Innocenti
2004-07-13 8:12 ` Richard Henderson
0 siblings, 1 reply; 11+ messages in thread
From: Bernardo Innocenti @ 2004-07-13 7:50 UTC (permalink / raw)
To: Andrew Pinski
Cc: GCC Patches, gdb-patches, binutils, Ian Lance Taylor, DJ Delorie
Andrew Pinski wrote:
>>this patch adds the ARG_UNUSED() macro to be used in place of
>>ATTRIBUTE_UNUSED. The syntax looks like this:
>>
>> void foo (ARG_UNUSED (int, x))
>> {
>> }
>>
>>The C++ frontend can't parse attribute((unused)) when it
>>appears after the variable name. The cleanest work-around
>>is using the standard C++ syntax to specify unused
>>parameters, which can also be used when bootstrapping from
>>other C++ compilers.
>>
>>This patch is a prerequisite for the upcoming C++ bootstrap
>>patches that I've been preparing.
>
>
> Huh? Yes it can from 3.4.0 and above.
Nevertheless, bootstrap from earlier versions of GCC
would fail (I was using Apple's version of GCC 3.3).
ansidecl.h enables ATTRIBUTE_UNUSED for any GCC > 2.7.
We could make the check stricter, like this:
#if !defined(__cplusplus) || GCC_VERSION >= 3004
#define ATTRIBUTE_UNUSED __attribute__ ((__unused__))
#endif
But I'd much prefer the ARG_UNUSED solution, which can
be made to work with and C or C++ compiler, using whatever
funny syntax the compiler requires.
This macro is in libiberty, which is about portability
across different OSes and compilers.
I also like the ARG_UNUSED syntax because it's somewhat
shorter to type. (btw, Doxygen can parse it if you
define ARG_UNUSED(T,N) to "T N").
--
// Bernardo Innocenti - Develer S.r.l., R&D dept.
\X/ http://www.develer.com/
^ permalink raw reply [flat|nested] 11+ messages in thread* Re: [libiberty] Add ARG_UNUSED as a C++-friendly replacement for ATTRIBUTE_UNUSED
2004-07-13 7:50 ` Bernardo Innocenti
@ 2004-07-13 8:12 ` Richard Henderson
2004-07-13 8:15 ` Bernardo Innocenti
[not found] ` <Pine.LNX.4.56.0407132255170.4658@hades.cambridge.redhat.com>
0 siblings, 2 replies; 11+ messages in thread
From: Richard Henderson @ 2004-07-13 8:12 UTC (permalink / raw)
To: Bernardo Innocenti
Cc: Andrew Pinski, GCC Patches, gdb-patches, binutils,
Ian Lance Taylor, DJ Delorie
On Tue, Jul 13, 2004 at 09:50:36AM +0200, Bernardo Innocenti wrote:
> define ARG_UNUSED(T,N) to "T N").
If we do this, I'd prefer
T ARG_UNUSED(N)
#ifdef __cplusplus
# define ARG_UNUSED(N)
#elif somegccversion
# define ARG_UNUSED(N) N ATTRIBUTE_UNUSED
#else
# define ARG_UNUSED(N) N
#endif
r~
^ permalink raw reply [flat|nested] 11+ messages in thread* Re: [libiberty] Add ARG_UNUSED as a C++-friendly replacement for ATTRIBUTE_UNUSED
2004-07-13 8:12 ` Richard Henderson
@ 2004-07-13 8:15 ` Bernardo Innocenti
2004-07-13 8:51 ` Richard Henderson
2004-07-13 17:11 ` Jason Merrill
[not found] ` <Pine.LNX.4.56.0407132255170.4658@hades.cambridge.redhat.com>
1 sibling, 2 replies; 11+ messages in thread
From: Bernardo Innocenti @ 2004-07-13 8:15 UTC (permalink / raw)
To: Richard Henderson
Cc: Andrew Pinski, GCC Patches, gdb-patches, binutils,
Ian Lance Taylor, DJ Delorie
Richard Henderson wrote:
> On Tue, Jul 13, 2004 at 09:50:36AM +0200, Bernardo Innocenti wrote:
>
>>define ARG_UNUSED(T,N) to "T N").
>
>
> If we do this, I'd prefer
>
> T ARG_UNUSED(N)
>
> #ifdef __cplusplus
> # define ARG_UNUSED(N)
> #elif somegccversion
> # define ARG_UNUSED(N) N ATTRIBUTE_UNUSED
> #else
> # define ARG_UNUSED(N) N
> #endif
This wouldn't allow us to support g++ < 3.4:
# define ARG_UNUSED(T,N) ATTRIBUTE_UNUSED T N
--
// Bernardo Innocenti - Develer S.r.l., R&D dept.
\X/ http://www.develer.com/
^ permalink raw reply [flat|nested] 11+ messages in thread* Re: [libiberty] Add ARG_UNUSED as a C++-friendly replacement for ATTRIBUTE_UNUSED
2004-07-13 8:15 ` Bernardo Innocenti
@ 2004-07-13 8:51 ` Richard Henderson
2004-07-13 17:11 ` Jason Merrill
1 sibling, 0 replies; 11+ messages in thread
From: Richard Henderson @ 2004-07-13 8:51 UTC (permalink / raw)
To: Bernardo Innocenti
Cc: Andrew Pinski, GCC Patches, gdb-patches, binutils,
Ian Lance Taylor, DJ Delorie
On Tue, Jul 13, 2004 at 10:15:47AM +0200, Bernardo Innocenti wrote:
> This wouldn't allow us to support g++ < 3.4:
>
> # define ARG_UNUSED(T,N) ATTRIBUTE_UNUSED T N
Well, frankly, I don't care. We don't build with -Werror
at stage1 for a reason.
r~
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [libiberty] Add ARG_UNUSED as a C++-friendly replacement for ATTRIBUTE_UNUSED
2004-07-13 8:15 ` Bernardo Innocenti
2004-07-13 8:51 ` Richard Henderson
@ 2004-07-13 17:11 ` Jason Merrill
1 sibling, 0 replies; 11+ messages in thread
From: Jason Merrill @ 2004-07-13 17:11 UTC (permalink / raw)
To: Bernardo Innocenti
Cc: Richard Henderson, Andrew Pinski, GCC Patches, gdb-patches,
binutils, Ian Lance Taylor, DJ Delorie
On Tue, 13 Jul 2004 10:15:47 +0200, Bernardo Innocenti <bernie@develer.com> wrote:
> Richard Henderson wrote:
>> On Tue, Jul 13, 2004 at 09:50:36AM +0200, Bernardo Innocenti wrote:
>>
>>>define ARG_UNUSED(T,N) to "T N").
>>
>>
>> If we do this, I'd prefer
>>
>> T ARG_UNUSED(N)
>>
>> #ifdef __cplusplus
>> # define ARG_UNUSED(N)
>> #elif somegccversion
>> # define ARG_UNUSED(N) N ATTRIBUTE_UNUSED
>> #else
>> # define ARG_UNUSED(N) N
>> #endif
>
> This wouldn't allow us to support g++ < 3.4:
>
> # define ARG_UNUSED(T,N) ATTRIBUTE_UNUSED T N
Huh? rth's definition above supports all C++ compilers just fine.
Jason
^ permalink raw reply [flat|nested] 11+ messages in thread
[parent not found: <Pine.LNX.4.56.0407132255170.4658@hades.cambridge.redhat.com>]
* Re: [libiberty] Add ARG_UNUSED as a C++-friendly replacement for ATTRIBUTE_UNUSED
[not found] ` <Pine.LNX.4.56.0407132255170.4658@hades.cambridge.redhat.com>
@ 2004-07-13 22:45 ` Bernardo Innocenti
0 siblings, 0 replies; 11+ messages in thread
From: Bernardo Innocenti @ 2004-07-13 22:45 UTC (permalink / raw)
To: Bernd Schmidt
Cc: Richard Henderson, Andrew Pinski, GCC Patches, gdb-patches,
binutils, Ian Lance Taylor, DJ Delorie
Bernd Schmidt wrote:
> On Tue, 13 Jul 2004, Richard Henderson wrote:
>>On Tue, Jul 13, 2004 at 09:50:36AM +0200, Bernardo Innocenti wrote:
>>
>>#ifdef __cplusplus
>># define ARG_UNUSED(N)
>>#elif somegccversion
>># define ARG_UNUSED(N) N ATTRIBUTE_UNUSED
>>#else
>># define ARG_UNUSED(N) N
>>#endif
>
> That fails in cases where the argument is unused only on some targets
> and needed by others.
For those (few) cases, I've handled it by moving ATTRIBUTE_UNUSED
before the typename, which seems to work G++ 3.3 too.
> What's wrong with just disabling ATTRIBUTE_UNUSED for compilers that
> can't handle it?
- You get lots of annoying warnings in stage1 and when building
a cross compiler;
- If we switch to C++, ARG_UNUSED would allow using the standard
C++ syntax for unused arguments;
- libiberty.h is used in other projects and it's about portability
across different compilers and platforms. The ATTRIBUTE_UNUSED
macro cannot be made to work usefully with all compilers,
therefore it must be replaced with something more portable;
- "int ARG_UNUSED(foo)" is shorter, more readable and sexier than
"int foo ATTRIBUTE_UNUSED".
--
// Bernardo Innocenti - Develer S.r.l., R&D dept.
\X/ http://www.develer.com/
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [libiberty] Add ARG_UNUSED as a C++-friendly replacement for ATTRIBUTE_UNUSED
2004-07-11 23:52 [libiberty] Add ARG_UNUSED as a C++-friendly replacement for ATTRIBUTE_UNUSED Bernardo Innocenti
2004-07-12 4:20 ` Andrew Pinski
@ 2004-07-12 14:01 ` Andrew Cagney
2004-07-12 19:09 ` DJ Delorie
2 siblings, 0 replies; 11+ messages in thread
From: Andrew Cagney @ 2004-07-12 14:01 UTC (permalink / raw)
To: Bernardo Innocenti
Cc: GCC Patches, gdb-patches, binutils, Ian Lance Taylor, DJ Delorie
Just FYI, GDB doesn't use ATTRIB_UNUSED (but thanks for resolving C++
problems with these macros).
Andrew
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [libiberty] Add ARG_UNUSED as a C++-friendly replacement for ATTRIBUTE_UNUSED
2004-07-11 23:52 [libiberty] Add ARG_UNUSED as a C++-friendly replacement for ATTRIBUTE_UNUSED Bernardo Innocenti
2004-07-12 4:20 ` Andrew Pinski
2004-07-12 14:01 ` Andrew Cagney
@ 2004-07-12 19:09 ` DJ Delorie
2004-07-13 8:05 ` Bernardo Innocenti
2 siblings, 1 reply; 11+ messages in thread
From: DJ Delorie @ 2004-07-12 19:09 UTC (permalink / raw)
To: bernie; +Cc: gcc-patches, gdb-patches, binutils, ian
This implementation doesn't address K&R style argument lists, although
that's soon to be a moot point ;-)
I'd also prefer this definition to be right after the ATTRIBUTE_UNUSED
definition, rather than randomly added to the end of the file.
However, I'm not convinced we need this yet. By the time we require a
C++ compiler, 3.4.0 will be old enough to require that version.
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [libiberty] Add ARG_UNUSED as a C++-friendly replacement for ATTRIBUTE_UNUSED
2004-07-12 19:09 ` DJ Delorie
@ 2004-07-13 8:05 ` Bernardo Innocenti
0 siblings, 0 replies; 11+ messages in thread
From: Bernardo Innocenti @ 2004-07-13 8:05 UTC (permalink / raw)
To: DJ Delorie; +Cc: gcc-patches, gdb-patches, binutils, ian
DJ Delorie wrote:
> This implementation doesn't address K&R style argument lists, although
> that's soon to be a moot point ;-)
Anyway, I think there's no way to get something like this to work:
foo (a, b, dummy)
char *a;
int b;
ARG_UNUSED (int, dummy);
{
}
> I'd also prefer this definition to be right after the ATTRIBUTE_UNUSED
> definition, rather than randomly added to the end of the file.
OK.
> However, I'm not convinced we need this yet. By the time we require a
> C++ compiler, 3.4.0 will be old enough to require that version.
So we won't be able to bootstrap from third-party C++ compilers?
The ATTRIBUTE_UNUSED macro cannot be made to work with MSVC, CW
or other popular compilers.
Not that I care that much: on any supported host you can always
install an older version of GCC or cross-compile from another host.
--
// Bernardo Innocenti - Develer S.r.l., R&D dept.
\X/ http://www.develer.com/
^ permalink raw reply [flat|nested] 11+ messages in thread
end of thread, other threads:[~2004-07-13 22:45 UTC | newest]
Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-07-11 23:52 [libiberty] Add ARG_UNUSED as a C++-friendly replacement for ATTRIBUTE_UNUSED Bernardo Innocenti
2004-07-12 4:20 ` Andrew Pinski
2004-07-13 7:50 ` Bernardo Innocenti
2004-07-13 8:12 ` Richard Henderson
2004-07-13 8:15 ` Bernardo Innocenti
2004-07-13 8:51 ` Richard Henderson
2004-07-13 17:11 ` Jason Merrill
[not found] ` <Pine.LNX.4.56.0407132255170.4658@hades.cambridge.redhat.com>
2004-07-13 22:45 ` Bernardo Innocenti
2004-07-12 14:01 ` Andrew Cagney
2004-07-12 19:09 ` DJ Delorie
2004-07-13 8:05 ` Bernardo Innocenti
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox