Perl

NAVIGATION
CATEGORIES
REFERRENCE
LINKS
  • gcc 3.3 has problems with __attribute__((unused))

    8 answers - 1508 bytes - related search similar search Add To My Delicious Add To My Stumble Upon Add To My Google Mark Add To My Facebook Add To My Digg Add To My Reddit

    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.
    perl-5.8.x/perl.h2006-06-27 17:56:06.000000000 -0400
    perl-5.8.x-andy/perl.h2006-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.
  • No.1 | | 1024 bytes | |

    Andrew Dougherty wrote:
    perl-5.8.x/perl.h 2006-06-27 17:56:06.000000000 -0400
    perl-5.8.x-andy/perl.h2006-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 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.
  • No.2 | | 1182 bytes | |

    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
    would be incorrectly named, as it wouldn't mean that the compiler has
    attribute unused. 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.

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

    <>
  • No.3 | | 997 bytes | |

    Thu, 29 Jun 2006, Andy Dougherty wrote:

    Wed, 28 Jun 2006, John Myers wrote:

    Neither the patch nor -DPERL_UNUSED_DECL= helps much 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.h2006-06-13 15:30:49.000000000 -0400
    perl-5.8.x-andy/XSUB.h2006-06-29 11:48:32.000000000 -0400
    @@ -99,7 +99,7 @@
    #if defined(__CYGWIN__) && defined(USE_DYNAMIC_LADING)
    # 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)

    , 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.
  • No.4 | | 2002 bytes | |

    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.h2006-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 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.h2006-06-13 15:30:49.000000000 -0400
    perl-5.8.x-andy/XSUB.h2006-06-29 11:48:32.000000000 -0400
    @@ -99,7 +99,7 @@
    #if defined(__CYGWIN__) && defined(USE_DYNAMIC_LADING)
    # 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.
  • No.5 | | 3120 bytes | |

    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 would
    be incorrectly named, as it wouldn't mean that the compiler has attribute
    unused. 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.

    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.

    perl-5.8.x/perl.h2006-06-27 17:56:06.000000000 -0400
    perl-5.8.x-andy/perl.h2006-06-29 13:18:25.000000000 -0400
    @@ -2442,6 +2442,9 @@
    * ,
    * but contrary to this information warn_unused_result seems
    * not to be in gcc 3.3.5, at least.
    + * 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.
    * 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_FRMAT).
    @@ -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_MINR__ >= 4 || __GNUC__ 3 /* 3.4 -*/
    + /* This actually works for gcc-3.3, but not for g3.3. */
    # define HASATTRIBUTE_UNUSED
    # endif
    # if __GNUC__ == 3 && __GNUC_MINR__ >= 4 || __GNUC__ 3 /* 3.4 -*/
  • No.6 | | 3322 bytes | |

    Thu, 29 Jun 2006 13:41:28 -0400 (EDT), Andrew Dougherty
    <doughera (AT) lafayette (DOT) eduwrote:

    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 would
    be incorrectly named, as it wouldn't mean that the compiler has attribute
    unused. 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.

    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.h2006-06-27 17:56:06.000000000 -0400
    perl-5.8.x-andy/perl.h2006-06-29 13:18:25.000000000 -0400
    @@ -2442,6 +2442,9 @@
    * ,
    * but contrary to this information warn_unused_result seems
    * not to be in gcc 3.3.5, at least.
    + * 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.
    * 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_FRMAT).
    @@ -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_MINR__ >= 4 || __GNUC__ 3 /* 3.4 -*/
    + /* This actually works for gcc-3.3, but not for g3.3. */
    # define HASATTRIBUTE_UNUSED
    # endif
    # if __GNUC__ == 3 && __GNUC_MINR__ >= 4 || __GNUC__ 3 /* 3.4 -*/
  • No.7 | | 999 bytes | |

    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 g3.3.
    the many equivalent ways of phrasing the conditionals, I thought this
    was clearest.

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

    perl-current/perl.h2006-07-10 07:30:15.000000000 -0400
    perl-andy/perl.h2006-07-10 13:04:38.000000000 -0400
    @@ -2604,9 +2604,11 @@
    # define HASATTRIBUTE_PURE
    # endif
    # if __GNUC__ == 3 && __GNUC_MINR__ >= 4 || __GNUC__ 3 /* 3.4 -*/
    - /* This actually works for gcc-3.3, but not for g3.3. */
    # define HASATTRIBUTE_UNUSED
    # endif
    +# if __GNUC__ == 3 && __GNUC_MINR__ == 3 && !defined(__cplusplus)
    +# define HASATTRIBUTE_UNUSED /* gcc-3.3, but not g3.3. */
    +# endif
    # if __GNUC__ == 3 && __GNUC_MINR__ >= 4 || __GNUC__ 3 /* 3.4 -*/
    # define
    # endif
  • No.8 | | 258 bytes | |

    Andy Dougherty wrote:
    Again, this should be suitable for both bleadperl and maintperl.
    perl-current/perl.h2006-07-10 07:30:15.000000000 -0400
    perl-andy/perl.h2006-07-10 13:04:38.000000000 -0400
    Thanks, applied as change #28541.

Re: gcc 3.3 has problems with __attribute__((unused))


max 4000 letters.
Your nickname that display:
In order to stop the spam: 0 + 9 =
QUESTION ON "Perl"

EMSDN.COM