Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gcc 3.3 has problems with __attribute__((unused)) #8500

Closed
p5pRT opened this issue Jun 26, 2006 · 18 comments
Closed

gcc 3.3 has problems with __attribute__((unused)) #8500

p5pRT opened this issue Jun 26, 2006 · 18 comments

Comments

@p5pRT
Copy link

p5pRT commented Jun 26, 2006

Migrated from rt.perl.org#39634 (status was 'resolved')

Searchable as RT39634$

@p5pRT
Copy link
Author

p5pRT commented Jun 26, 2006

From jgmyers@proofpoint.com

Created by jgmyers@pong.us.proofpoint.com

[jgmyers@​pong jgmyers]$ cat test.c
extern "C" {
void (*foo) (int *bar __attribute__((unused)), void*);
}
[jgmyers@​pong jgmyers]$ gcc-3.3 -x c++ test.c
test.c​:2​: error​: parse error before `__attribute__'
test.c​:2​: error​: syntax error before `)' token

Perl Info

Flags:
    category=core
    severity=low

Site configuration information for perl v5.8.8:

Configured by xtools at Thu Mar 23 18:09:06 PST 2006.

Summary of my perl5 (revision 5 version 8 subversion 8) configuration:
  Platform:
    osname=linux, osvers=2.4.20-28.8smp, archname=i686-linux-thread-multi
    uname='linux xenon2 2.4.20-28.8smp #1 smp thu dec 18 12:25:21 est 
2003 i686 i686 i386 gnulinux '
    config_args='-Dcc=gcc -Dprefix=/tools/x/perl-5.8.8 
-Uinstallusrbinperl -Dusethreads -de -Dlibpth=/lib /usr/lib 
-Dlocincpth=/usr/include'
    hint=recommended, useposix=true, d_sigaction=define
    usethreads=define use5005threads=undef useithreads=define 
usemultiplicity=define
    useperlio=define d_sfio=undef uselargefiles=define usesocks=undef
    use64bitint=undef use64bitall=undef uselongdouble=undef
    usemymalloc=n, bincompat5005=undef
  Compiler:
    cc='gcc', ccflags ='-D_REENTRANT -D_GNU_SOURCE -DTHREADS_HAVE_PIDS 
-fno-strict-aliasing -pipe -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 
-I/usr/include/gdbm',
    optimize='-O2',
    cppflags='-D_REENTRANT -D_GNU_SOURCE -DTHREADS_HAVE_PIDS 
-fno-strict-aliasing -pipe -I/usr/include/gdbm'
    ccversion='', gccversion='3.3.3', gccosandvers=''
    intsize=4, longsize=4, ptrsize=4, doublesize=8, byteorder=1234
    d_longlong=define, longlongsize=8, d_longdbl=define, longdblsize=12
    ivtype='long', ivsize=4, nvtype='double', nvsize=8, Off_t='off_t', 
lseeksize=8
    alignbytes=4, prototype=define
  Linker and Libraries:
    ld='gcc', ldflags =''
    libpth=/lib /usr/lib
    libs=-lnsl -lgdbm -ldb -ldl -lm -lcrypt -lutil -lpthread -lc
    perllibs=-lnsl -ldl -lm -lcrypt -lutil -lpthread -lc
    libc=/lib/libc-2.3.2.so, so=so, useshrplib=false, libperl=libperl.a
    gnulibc_version='2.3.2'
  Dynamic Linking:
    dlsrc=dl_dlopen.xs, dlext=so, d_dlsymun=undef, ccdlflags='-Wl,-E'
    cccdlflags='-fpic', lddlflags='-shared'

Locally applied patches:
    


@INC for perl v5.8.8:
    /tools/x/perl-5.8.8/lib/5.8.8/i686-linux-thread-multi
    /tools/x/perl-5.8.8/lib/5.8.8
    /tools/x/perl-5.8.8/lib/site_perl/5.8.8/i686-linux-thread-multi
    /tools/x/perl-5.8.8/lib/site_perl/5.8.8
    /tools/x/perl-5.8.8/lib/site_perl
    .


Environment for perl v5.8.8:
    HOME=/u/jgmyers
    LANG=en_US
    LANGUAGE (unset)
    LD_LIBRARY_PATH (unset)
    LOGDIR (unset)
    
PATH=/tools/x/bin:/usr/kerberos/bin:/usr/local/bin:/bin:/usr/bin:/usr/X11R6/bin:/u/jgmyers/bin
    PERL_BADLANG (unset)
    SHELL=/bin/bash

@p5pRT
Copy link
Author

p5pRT commented Jun 26, 2006

From guest@guest.guest.xxxxxxxx

Proposed fix

@p5pRT
Copy link
Author

p5pRT commented Jun 26, 2006

@p5pRT
Copy link
Author

p5pRT commented Jun 26, 2006

The RT System itself - Status changed from 'new' to 'open'

@p5pRT
Copy link
Author

p5pRT commented Jun 27, 2006

From @smpeters

On Mon, Jun 26, 2006 at 03​:43​:35PM -0700, John Gardiner Myers wrote​:

# New Ticket Created by John Gardiner Myers
# Please include the string​: [perl #39634]
# in the subject line of all future correspondence about this issue.
# <URL​: https://rt-archive.perl.org/perl5/Ticket/Display.html?id=39634 >

This is a bug report for perl from jgmyers@​pong.us.proofpoint.com,
generated with the help of perlbug 1.35 running under perl v5.8.8.

-----------------------------------------------------------------
[Please enter your report here]

[jgmyers@​pong jgmyers]$ cat test.c
extern "C" {
void (*foo) (int *bar __attribute__((unused)), void*);
}
[jgmyers@​pong jgmyers]$ gcc-3.3 -x c++ test.c
test.c​:2​: error​: parse error before `__attribute__'
test.c​:2​: error​: syntax error before `)' token

What errors specifically do you see when compiling Perl?

Steve Peters
steve@​fisharerojo.org

@p5pRT
Copy link
Author

p5pRT commented Jun 27, 2006

From jgmyers@proofpoint.com

Steve Peters via RT wrote​:

What errors specifically do you see when compiling Perl?
The errors are when compiling perl extensions​:

cc -Isrc -I/usr/lib/perl5/5.8.8/i686-linux-thread-multi/CORE
-DXS_VERSION="0.01" -DVERSION="0.01" -fpic -x c++ -Iinclude -c
-D_REENTRANT -D_GNU_SOURCE -DTHREADS_HAVE_PIDS -fno-strict-aliasing
-pipe -I/usr/local/include -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64
-O2 -o lib/Encode/Detect/Detector.o lib/Encode/Detect/Detector.c
In file included from lib/Encode/Detect/Detector.xs​:40​:
/usr/lib/perl5/5.8.8/i686-linux-thread-multi/CORE/perl.h​:2700​: error​: parse
  error before `__attribute__'
/usr/lib/perl5/5.8.8/i686-linux-thread-multi/CORE/perl.h​:2710​: error​: parse
  error before `__attribute__'
/usr/lib/perl5/5.8.8/i686-linux-thread-multi/CORE/perl.h​:2710​: error​:
syntax
  error before `)' token
In file included from
/usr/lib/perl5/5.8.8/i686-linux-thread-multi/CORE/iperlsys.h​:51,
  from
/usr/lib/perl5/5.8.8/i686-linux-thread-multi/CORE/perl.h​:2733,
  from lib/Encode/Detect/Detector.xs​:40​:
/usr/lib/perl5/5.8.8/i686-linux-thread-multi/CORE/perlio.h​:117​: error​:
parse
  error before `__attribute__'
/usr/lib/perl5/5.8.8/i686-linux-thread-multi/CORE/perlio.h​: In function
`void
  PerlIO_define_layer(...)'​:
/usr/lib/perl5/5.8.8/i686-linux-thread-multi/CORE/perlio.h​:118​: error​:
parse
  error before `__attribute__'
/usr/lib/perl5/5.8.8/i686-linux-thread-multi/CORE/perlio.h​: In function `
  PerlIO_funcs* PerlIO_find_layer(...)'​:
/usr/lib/perl5/5.8.8/i686-linux-thread-multi/CORE/perlio.h​:121​: error​:
parse
  error before `__attribute__'
/usr/lib/perl5/5.8.8/i686-linux-thread-multi/CORE/perlio.h​: In function `
  PerlIOl** PerlIO_push(...)'​:
/usr/lib/perl5/5.8.8/i686-linux-thread-multi/CORE/perlio.h​:123​: error​:
parse
  error before `__attribute__'
/usr/lib/perl5/5.8.8/i686-linux-thread-multi/CORE/perlio.h​: In function
`void
  PerlIO_pop(...)'​:
/usr/lib/perl5/5.8.8/i686-linux-thread-multi/CORE/perlio.h​:124​: error​:
parse
  error before `__attribute__'
/usr/lib/perl5/5.8.8/i686-linux-thread-multi/CORE/perlio.h​: In function
`AV*
  PerlIO_get_layers(...)'​:
/usr/lib/perl5/5.8.8/i686-linux-thread-multi/CORE/perlio.h​:125​: error​:
parse
  error before `__attribute__'
/usr/lib/perl5/5.8.8/i686-linux-thread-multi/CORE/perlio.h​: In function
`void
  PerlIO_clone(...)'​:
/usr/lib/perl5/5.8.8/i686-linux-thread-multi/CORE/perlio.h​:220​: error​:
parse
  error before `__attribute__'
/usr/lib/perl5/5.8.8/i686-linux-thread-multi/CORE/perlio.h​: In function
`void
  PerlIO_init(...)'​:
/usr/lib/perl5/5.8.8/i686-linux-thread-multi/CORE/perlio.h​:233​: error​:
parse
  error before `__attribute__'
/usr/lib/perl5/5.8.8/i686-linux-thread-multi/CORE/perlio.h​: In function `
  PerlIOl** PerlIO_openn(...)'​:
/usr/lib/perl5/5.8.8/i686-linux-thread-multi/CORE/perlio.h​:351​: error​:
parse
  error before `__attribute__'
/usr/lib/perl5/5.8.8/i686-linux-thread-multi/CORE/perlio.h​: In function `
  PerlIOl** PerlIO_fdupopen(...)'​:
/usr/lib/perl5/5.8.8/i686-linux-thread-multi/CORE/perlio.h​:360​: error​:
parse
  error before `__attribute__'
/usr/lib/perl5/5.8.8/i686-linux-thread-multi/CORE/perlio.h​: In function
`int
  PerlIO_apply_layers(...)'​:
/usr/lib/perl5/5.8.8/i686-linux-thread-multi/CORE/perlio.h​:364​: error​:
parse
  error before `__attribute__'
/usr/lib/perl5/5.8.8/i686-linux-thread-multi/CORE/perlio.h​: In function
`int
  PerlIO_binmode(...)'​:
/usr/lib/perl5/5.8.8/i686-linux-thread-multi/CORE/perlio.h​:371​: error​:
parse
  error before `__attribute__'
/usr/lib/perl5/5.8.8/i686-linux-thread-multi/CORE/perlio.h​: In function
`void
  PerlIO_destruct(...)'​:
/usr/lib/perl5/5.8.8/i686-linux-thread-multi/CORE/perlio.h​:376​: error​:
parse
  error before `__attribute__'
In file included from
/usr/lib/perl5/5.8.8/i686-linux-thread-multi/CORE/perl.h​:2746,
  from lib/Encode/Detect/Detector.xs​:40​:
/usr/lib/perl5/5.8.8/i686-linux-thread-multi/CORE/regexp.h​: In function
`void
  PerlIO_cleanup(...)'​:
/usr/lib/perl5/5.8.8/i686-linux-thread-multi/CORE/regexp.h​:31​: error​:
declaration
  of `struct regexp' in `void PerlIO_cleanup(...)' which does not
enclose `​::'
/usr/lib/perl5/5.8.8/i686-linux-thread-multi/CORE/regexp.h​:31​: confused
by earlier errors, bailing out
error building lib/Encode/Detect/Detector.o from
'lib/Encode/Detect/Detector.c' at
/usr/lib/perl5/site_perl/5.8.8/ExtUtils/CBuilder/Base.pm line 108.

@p5pRT
Copy link
Author

p5pRT commented Jun 27, 2006

From @doughera88

On Mon, 26 Jun 2006, John Gardiner Myers wrote​:

# New Ticket Created by John Gardiner Myers
# Please include the string​: [perl #39634]
# in the subject line of all future correspondence about this issue.
# <URL​: https://rt-archive.perl.org/perl5/Ticket/Display.html?id=39634 >

[jgmyers@​pong jgmyers]$ cat test.c
extern "C" {
void (*foo) (int *bar __attribute__((unused)), void*);
}
[jgmyers@​pong jgmyers]$ gcc-3.3 -x c++ test.c
test.c​:2​: error​: parse error before `__attribute__'
test.c​:2​: error​: syntax error before `)' token

What's the -x c++ flag there for, and how did it get there? If it was
included in the flags supplied to Configure, then did Configure get the
attribute test wrong? (I don't see any -x c++ in the perlbug info below,
but I suspect that's from a different build, and hence not really
relevant.)

[Please do not change anything below this line]
-----------------------------------------------------------------
---
Flags​:
category=core
severity=low
---
Site configuration information for perl v5.8.8​:

Configured by xtools at Thu Mar 23 18​:09​:06 PST 2006.

Summary of my perl5 (revision 5 version 8 subversion 8) configuration​:
Platform​:
osname=linux, osvers=2.4.20-28.8smp, archname=i686-linux-thread-multi
uname='linux xenon2 2.4.20-28.8smp #1 smp thu dec 18 12​:25​:21 est
2003 i686 i686 i386 gnulinux '
config_args='-Dcc=gcc -Dprefix=/tools/x/perl-5.8.8
-Uinstallusrbinperl -Dusethreads -de -Dlibpth=/lib /usr/lib
-Dlocincpth=/usr/include'
hint=recommended, useposix=true, d_sigaction=define
usethreads=define use5005threads=undef useithreads=define
usemultiplicity=define
useperlio=define d_sfio=undef uselargefiles=define usesocks=undef
use64bitint=undef use64bitall=undef uselongdouble=undef
usemymalloc=n, bincompat5005=undef
Compiler​:
cc='gcc', ccflags ='-D_REENTRANT -D_GNU_SOURCE -DTHREADS_HAVE_PIDS
-fno-strict-aliasing -pipe -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64
-I/usr/include/gdbm',
optimize='-O2',
cppflags='-D_REENTRANT -D_GNU_SOURCE -DTHREADS_HAVE_PIDS
-fno-strict-aliasing -pipe -I/usr/include/gdbm'
ccversion='', gccversion='3.3.3', gccosandvers=''
intsize=4, longsize=4, ptrsize=4, doublesize=8, byteorder=1234
d_longlong=define, longlongsize=8, d_longdbl=define, longdblsize=12
ivtype='long', ivsize=4, nvtype='double', nvsize=8, Off_t='off_t',
lseeksize=8
alignbytes=4, prototype=define
Linker and Libraries​:
ld='gcc', ldflags =''
libpth=/lib /usr/lib
libs=-lnsl -lgdbm -ldb -ldl -lm -lcrypt -lutil -lpthread -lc
perllibs=-lnsl -ldl -lm -lcrypt -lutil -lpthread -lc
libc=/lib/libc-2.3.2.so, so=so, useshrplib=false, libperl=libperl.a
gnulibc_version='2.3.2'
Dynamic Linking​:
dlsrc=dl_dlopen.xs, dlext=so, d_dlsymun=undef, ccdlflags='-Wl,-E'
cccdlflags='-fpic', lddlflags='-shared'

Locally applied patches​:

---
@​INC for perl v5.8.8​:
/tools/x/perl-5.8.8/lib/5.8.8/i686-linux-thread-multi
/tools/x/perl-5.8.8/lib/5.8.8
/tools/x/perl-5.8.8/lib/site_perl/5.8.8/i686-linux-thread-multi
/tools/x/perl-5.8.8/lib/site_perl/5.8.8
/tools/x/perl-5.8.8/lib/site_perl
.

---
Environment for perl v5.8.8​:
HOME=/u/jgmyers
LANG=en_US
LANGUAGE (unset)
LD_LIBRARY_PATH (unset)
LOGDIR (unset)

PATH=/tools/x/bin​:/usr/kerberos/bin​:/usr/local/bin​:/bin​:/usr/bin​:/usr/X11R6/bin​:/u/jgmyers/bin
PERL_BADLANG (unset)
SHELL=/bin/bash

--
  Andy Dougherty doughera@​lafayette.edu

@p5pRT
Copy link
Author

p5pRT commented Jun 27, 2006

From jgmyers@proofpoint.com

Andy Dougherty via RT wrote​:

What's the -x c++ flag there for, and how did it get there?
It is in there because the XS code, part of Encode​::Detect, is written
in C++. It got in there by being included in extra_compiler_flags in
the Build.PL

@p5pRT
Copy link
Author

p5pRT commented Jun 28, 2006

From @doughera88

On Tue, 27 Jun 2006, John Gardiner Myers wrote​:

Andy Dougherty via RT wrote​:

What's the -x c++ flag there for, and how did it get there?
It is in there because the XS code, part of Encode​::Detect, is written in C++.
It got in there by being included in extra_compiler_flags in the Build.PL

Ah. I'd never heard of Encode​::Detect before. So if I understand
correctly, gcc-3.3's C compiler does handle __attribute__((unused)) as
detected by the Configure probes, but gcc-3.3's C++ compiler doesn't.

Hmm. Tricky. While that's certainly surprising and inconvenient
behavior, I don't think it's likely to change. Fortunately, I think you
can work around it fairly easily.

For the moment, I think if you just #define PERL_UNUSED_DECL at the top of
your .xs file before perl.h is included (or put -DPERL_UNUSED_DECL into
ccflags), then the attribute stuff won't get used.

Longer term, we should probably apply this patch from bleadperl to the
maintenance track, which does this automatically.

Inline Patch
--- perl-5.8.x/perl.h	2006-06-27 17:56:06.000000000 -0400
+++ perl-5.8.x-andy/perl.h	2006-06-28 15:09:27.000000000 -0400
@@ -164,7 +164,7 @@
 #endif
 
 #ifndef PERL_UNUSED_DECL
-#  ifdef HASATTRIBUTE_UNUSED
+#  if defined(HASATTRIBUTE_UNUSED) && !defined(__cplusplus)
 #    define PERL_UNUSED_DECL __attribute__unused__
 #  else
 #    define PERL_UNUSED_DECL



Please let us know if this helps.

--
  Andy Dougherty doughera@​lafayette.edu

@p5pRT
Copy link
Author

p5pRT commented Jun 28, 2006

From jgmyers@proofpoint.com

Andrew Dougherty wrote​:

--- perl-5.8.x/perl.h 2006-06-27 17​:56​:06.000000000 -0400
+++ perl-5.8.x-andy/perl.h 2006-06-28 15​:09​:27.000000000 -0400
@​@​ -164,7 +164,7 @​@​
#endif

#ifndef PERL_UNUSED_DECL
-# ifdef HASATTRIBUTE_UNUSED
+# if defined(HASATTRIBUTE_UNUSED) && !defined(__cplusplus)
# define PERL_UNUSED_DECL __attribute__unused__
# else
# define PERL_UNUSED_DECL

Please let us know if this helps.

That patch has the undesired effect of disabling the use of
__attribute__((unused)) in the C++ compiler for gcc-3.4 and later, for
which the directive works.

Neither the patch nor -DPERL_UNUSED_DECL= helps much--the compile then
trips over the use of __attribute__unused__ by the XS() macro defined in
XSUB.h

I think my proposed patch is the best one. __attribute__((unused)) is
only helpful for suppressing compiler warnings. It is not that
important to have it be enabled for older versions of gcc.

@p5pRT
Copy link
Author

p5pRT commented Jun 29, 2006

From @doughera88

On Wed, 28 Jun 2006, John Myers wrote​:

Andrew Dougherty wrote​:

--- perl-5.8.x/perl.h 2006-06-27 17​:56​:06.000000000 -0400
+++ perl-5.8.x-andy/perl.h 2006-06-28 15​:09​:27.000000000 -0400
@​@​ -164,7 +164,7 @​@​
#endif
#ifndef PERL_UNUSED_DECL
-# ifdef HASATTRIBUTE_UNUSED
+# if defined(HASATTRIBUTE_UNUSED) && !defined(__cplusplus)
# define PERL_UNUSED_DECL __attribute__unused__
# else
# define PERL_UNUSED_DECL

Please let us know if this helps.

That patch has the undesired effect of disabling the use of
__attribute__((unused)) in the C++ compiler for gcc-3.4 and later, for which
the directive works.

Well, this patch is what bleadperl does. Yes, it hits the problem with a
sledgehammer, but chasing gcc's warning flags across versions (and now
across compilers) happens to be an on-going wearisome topic elsewhere on
perl5-porters at the moment, and it's hard to muster much enthusiasm for
it :-).

Neither the patch nor -DPERL_UNUSED_DECL= helps much--the compile then trips
over the use of __attribute__unused__ by the XS() macro defined in XSUB.h

Ah, ok. Then XSUB.h probably needs the same patch. Something like this,
again taken from bleadperl.

Inline Patch
--- perl-5.8.x/XSUB.h	2006-06-13 15:30:49.000000000 -0400
+++ perl-5.8.x-andy/XSUB.h	2006-06-29 11:48:32.000000000 -0400
@@ -99,7 +99,7 @@
 #if defined(__CYGWIN__) && defined(USE_DYNAMIC_LOADING)
 #  define XS(name) __declspec(dllexport) void name(pTHX_ CV* cv)
 #else
-#  ifdef HASATTRIBUTE_UNUSED
+#  if defined(HASATTRIBUTE_UNUSED) && !defined(__cplusplus)
 #    define XS(name) void name(pTHX_ CV* cv __attribute__unused__)
 #  else
 #    define XS(name) void name(pTHX_ CV* cv)


> > I think my proposed patch is the best one\. \_\_attribute\_\_\(\(unused\)\) is only > helpful for suppressing compiler warnings\. It is not that important to have > it be enabled for older versions of gcc\.

What proposed patch? I didn't see one anywhere.

--
  Andy Dougherty doughera@​lafayette.edu

@p5pRT
Copy link
Author

p5pRT commented Jun 29, 2006

From jgmyers@proofpoint.com

Andy Dougherty wrote​:

Well, this patch is what bleadperl does. Yes, it hits the problem with a
sledgehammer, but chasing gcc's warning flags across versions (and now
across compilers) happens to be an on-going wearisome topic elsewhere on
perl5-porters at the moment, and it's hard to muster much enthusiasm for
it :-).

It's much more important for warnings to be suppressed in newer
compilers than in older compilers. Such patches should err on the side
of sledgehammering the older versions of compilers.

Ah, ok. Then XSUB.h probably needs the same patch. Something like this,
again taken from bleadperl.

You'd need to also do that change for any other reference to
HASATTRIBUTE_UNUSED. But that's really just wrong--HASATTRIBUTE_UNUSED
would be incorrectly named, as it wouldn't mean that the compiler has
attribute unused. One should change the code to not define that macro
if the compiler doesn't support the feature.

What proposed patch? I didn't see one anywhere.

The one attached to this bug.
http​://rt.perl.org/rt3/Ticket/Attachment/135364/90935/perl-attrib.diff

And yes, your bug tracking system leaves much to be desired.

<http​://rt.perl.org/rt3/Ticket/Attachment/135364/90935/perl-attrib.diff>

@p5pRT
Copy link
Author

p5pRT commented Jun 29, 2006

From @doughera88

On Thu, 29 Jun 2006, Andy Dougherty wrote​:

On Wed, 28 Jun 2006, John Myers wrote​:

Neither the patch nor -DPERL_UNUSED_DECL= helps much--the compile then trips
over the use of __attribute__unused__ by the XS() macro defined in XSUB.h

Ah, ok. Then XSUB.h probably needs the same patch. Something like this,
again taken from bleadperl.

--- perl-5.8.x/XSUB.h 2006-06-13 15​:30​:49.000000000 -0400
+++ perl-5.8.x-andy/XSUB.h 2006-06-29 11​:48​:32.000000000 -0400
@​@​ -99,7 +99,7 @​@​
#if defined(__CYGWIN__) && defined(USE_DYNAMIC_LOADING)
# define XS(name) __declspec(dllexport) void name(pTHX_ CV* cv)
#else
-# ifdef HASATTRIBUTE_UNUSED
+# if defined(HASATTRIBUTE_UNUSED) && !defined(__cplusplus)
# define XS(name) void name(pTHX_ CV* cv __attribute__unused__)
# else
# define XS(name) void name(pTHX_ CV* cv)

Oh, and I forgot -- a quick workaround is to add #undef
HASATTRIBUTE_UNUSED to your .xs file after perl.h has been included, but
before XSUB.h.

--
  Andy Dougherty doughera@​lafayette.edu

@p5pRT
Copy link
Author

p5pRT commented Jun 29, 2006

From @doughera88

On Thu, 29 Jun 2006, John Myers wrote​:

Andy Dougherty wrote​:

Well, this patch is what bleadperl does. Yes, it hits the problem with a
sledgehammer, but chasing gcc's warning flags across versions (and now
across compilers) happens to be an on-going wearisome topic elsewhere on
perl5-porters at the moment, and it's hard to muster much enthusiasm for it
:-).

It's much more important for warnings to be suppressed in newer compilers than
in older compilers. Such patches should err on the side of sledgehammering
the older versions of compilers.

Ah, ok. Then XSUB.h probably needs the same patch. Something like this,
again taken from bleadperl.

You'd need to also do that change for any other reference to
HASATTRIBUTE_UNUSED. But that's really just wrong--HASATTRIBUTE_UNUSED would
be incorrectly named, as it wouldn't mean that the compiler has attribute
unused. One should change the code to not define that macro if the compiler
doesn't support the feature.

Well, my confusion arose because the C compiler *did* support the feature,
but the C++ compiler didn't. Configure tests the C compiler. It doesn't
test the C++ compiler.

What proposed patch? I didn't see one anywhere.

The one attached to this bug.
http​://rt.perl.org/rt3/Ticket/Attachment/135364/90935/perl-attrib.diff

Ah. I hadn't seen that. I had only been following along in the mailing
list. I don't know why that didn't get sent to the list. That would have
simplified this discussion considerably.

Yes, your patch is probably better overall. I had forgotten about that
section of perl.h. I've taken the liberty of adding a few comments at the
top of the section about its role in relation to the Configure probes for
these features. I think more comments are needed, but I need to do more
thinking first.

Nick and Rafael -- I've cc'd you because I think *this* version of the
patches in this thread is suitable for both maint and blead versions.

Inline Patch
--- perl-5.8.x/perl.h	2006-06-27 17:56:06.000000000 -0400
+++ perl-5.8.x-andy/perl.h	2006-06-29 13:18:25.000000000 -0400
@@ -2442,6 +2442,9 @@
  * http://www.ohse.de/uwe/articles/gcc-attributes.html,
  * but contrary to this information warn_unused_result seems
  * not to be in gcc 3.3.5, at least. --jhi
+ * Also, when building extensions with an installed perl, this allows
+ * the user to upgrade gcc and get the right attributes, rather than
+ * relying on the list generated at Configure time.  --AD
  * Set these up now otherwise we get confused when some of the <*thread.h>
  * includes below indirectly pull in <perlio.h> (which needs to know if we
  * have HASATTRIBUTE_FORMAT).
@@ -2463,7 +2466,8 @@
 #  if __GNUC__ >= 3 /* gcc 3.0 -> */
 #    define HASATTRIBUTE_PURE
 #  endif
-#  if __GNUC__ >= 3 /* gcc 3.0 -> */ /* XXX Verify this version */
+#  if __GNUC__ == 3 && __GNUC_MINOR__ >= 4 || __GNUC__ > 3 /* 3.4 -> */
+     /* This actually works for gcc-3.3, but not for g++-3.3. */
 #    define HASATTRIBUTE_UNUSED
 #  endif
 #  if __GNUC__ == 3 && __GNUC_MINOR__ >= 4 || __GNUC__ > 3 /* 3.4 -> */


-- 

  Andy Dougherty doughera@​lafayette.edu

@p5pRT
Copy link
Author

p5pRT commented Jun 30, 2006

From @Tux

On Thu, 29 Jun 2006 13​:41​:28 -0400 (EDT), Andrew Dougherty
<doughera@​lafayette.edu> wrote​:

On Thu, 29 Jun 2006, John Myers wrote​:

Andy Dougherty wrote​:

Well, this patch is what bleadperl does. Yes, it hits the problem with a
sledgehammer, but chasing gcc's warning flags across versions (and now
across compilers) happens to be an on-going wearisome topic elsewhere on
perl5-porters at the moment, and it's hard to muster much enthusiasm for it
:-).

It's much more important for warnings to be suppressed in newer compilers than
in older compilers. Such patches should err on the side of sledgehammering
the older versions of compilers.

Ah, ok. Then XSUB.h probably needs the same patch. Something like this,
again taken from bleadperl.

You'd need to also do that change for any other reference to
HASATTRIBUTE_UNUSED. But that's really just wrong--HASATTRIBUTE_UNUSED would
be incorrectly named, as it wouldn't mean that the compiler has attribute
unused. One should change the code to not define that macro if the compiler
doesn't support the feature.

Well, my confusion arose because the C compiler *did* support the feature,
but the C++ compiler didn't. Configure tests the C compiler. It doesn't
test the C++ compiler.

What proposed patch? I didn't see one anywhere.

The one attached to this bug.
http​://rt.perl.org/rt3/Ticket/Attachment/135364/90935/perl-attrib.diff

Ah. I hadn't seen that. I had only been following along in the mailing
list. I don't know why that didn't get sent to the list. That would have
simplified this discussion considerably.

Yes, your patch is probably better overall. I had forgotten about that
section of perl.h. I've taken the liberty of adding a few comments at the
top of the section about its role in relation to the Configure probes for
these features. I think more comments are needed, but I need to do more
thinking first.

Nick and Rafael -- I've cc'd you because I think *this* version of the
patches in this thread is suitable for both maint and blead versions.

I'm neither Nicholas, nor Rafael, but applied this patch as
change #28453 to blead. Thanks

--- perl-5.8.x/perl.h 2006-06-27 17​:56​:06.000000000 -0400
+++ perl-5.8.x-andy/perl.h 2006-06-29 13​:18​:25.000000000 -0400
@​@​ -2442,6 +2442,9 @​@​
* http​://www.ohse.de/uwe/articles/gcc-attributes.html,
* but contrary to this information warn_unused_result seems
* not to be in gcc 3.3.5, at least. --jhi
+ * Also, when building extensions with an installed perl, this allows
+ * the user to upgrade gcc and get the right attributes, rather than
+ * relying on the list generated at Configure time. --AD
* Set these up now otherwise we get confused when some of the <*thread.h>
* includes below indirectly pull in <perlio.h> (which needs to know if we
* have HASATTRIBUTE_FORMAT).
@​@​ -2463,7 +2466,8 @​@​
# if __GNUC__ >= 3 /* gcc 3.0 -> */
# define HASATTRIBUTE_PURE
# endif
-# if __GNUC__ >= 3 /* gcc 3.0 -> */ /* XXX Verify this version */
+# if __GNUC__ == 3 && __GNUC_MINOR__ >= 4 || __GNUC__ > 3 /* 3.4 -> */
+ /* This actually works for gcc-3.3, but not for g++-3.3. */
# define HASATTRIBUTE_UNUSED
# endif
# if __GNUC__ == 3 && __GNUC_MINOR__ >= 4 || __GNUC__ > 3 /* 3.4 -> */

--
H.Merijn Brand Amsterdam Perl Mongers (http​://amsterdam.pm.org/)
using & porting perl 5.6.2, 5.8.x, 5.9.x on HP-UX 10.20, 11.00, 11.11,
& 11.23, SuSE 10.0, AIX 4.3 & 5.2, and Cygwin. http​://qa.perl.org
http​://mirrors.develooper.com/hpux/ http​://www.test-smoke.org
  http​://www.goldmark.org/jeff/stupid-disclaimers/

@p5pRT
Copy link
Author

p5pRT commented Jul 5, 2006

@smpeters - Status changed from 'open' to 'resolved'

@p5pRT p5pRT closed this as completed Jul 5, 2006
@p5pRT
Copy link
Author

p5pRT commented Jul 10, 2006

From @doughera88

On Thu, 29 Jun 2006, Andrew Dougherty wrote​:

[patch already applied to bleadperl]

Upon further testing, I think this refinement is in order. It
re-activates the __attribute__((unused)) for gcc-3.3, but not g++-3.3.
Of the many equivalent ways of phrasing the conditionals, I thought this
was clearest.

Again, this should be suitable for both bleadperl and maintperl.

Inline Patch
--- perl-current/perl.h	2006-07-10 07:30:15.000000000 -0400
+++ perl-andy/perl.h	2006-07-10 13:04:38.000000000 -0400
@@ -2604,9 +2604,11 @@
 #    define HASATTRIBUTE_PURE
 #  endif
 #  if __GNUC__ == 3 && __GNUC_MINOR__ >= 4 || __GNUC__ > 3 /* 3.4 -> */
-     /* This actually works for gcc-3.3, but not for g++-3.3. */
 #    define HASATTRIBUTE_UNUSED
 #  endif
+#  if __GNUC__ == 3 && __GNUC_MINOR__ == 3 && !defined(__cplusplus)
+#    define HASATTRIBUTE_UNUSED /* gcc-3.3, but not g++-3.3. */
+#  endif
 #  if __GNUC__ == 3 && __GNUC_MINOR__ >= 4 || __GNUC__ > 3 /* 3.4 -> */
 #    define HASATTRIBUTE_WARN_UNUSED_RESULT
 #  endif


-- 

  Andy Dougherty doughera@​lafayette.edu

@p5pRT
Copy link
Author

p5pRT commented Jul 11, 2006

From @rgs

Andy Dougherty wrote​:

Again, this should be suitable for both bleadperl and maintperl.

--- perl-current/perl.h 2006-07-10 07​:30​:15.000000000 -0400
+++ perl-andy/perl.h 2006-07-10 13​:04​:38.000000000 -0400

Thanks, applied as change #28541.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant