Front page | perl.perl5.porters |
Postings from December 2012
Re: SvUPGRADE and void
Thread Previous
From:
H.Merijn Brand
Date:
December 14, 2012 07:36
Subject:
Re: SvUPGRADE and void
Message ID:
20121214083623.5388a92f@pc09.procura.nl
On Thu, 13 Dec 2012 13:14:28 +0000, Dave Mitchell <davem@iabyn.com>
wrote:
> SvUPGRADE() generates lots of 'warning: expression result unused' clang
> warnings.
>
> The reason is that historically sv_upgrade() and its SvUPGRADE() wrapper,
> used to return a boolean value indicating success; for example, there's
> CPAN code around like
>
> if (!SvUPGRADE(sv, SVt_PVMG))
> croak("Cannot upgrade variable");
>
> 7 years ago, with commit 63f971906e, sv_upgrade() was changed to be a void
> function, because it always croaked on error, and hadn't ever actually
> returned a false value.
>
> With that commit the SvUPGRADE macro was also documented as returning
> void, but was actually changed to always return a true value.
>
> There seem to be two ways of silencing these warnings.
>
> The first is to stick a (void) in front of every bare SvUPGRADE() in the
> the perl distribution (including dist/ and, via rt.cpan.org, cpan/).
> This seems like quite a bit of effort and is a retrograde step.
This is what I did in Text::CSV_XS after the same report from clang
> The second is to bite the bullet and change SvUPGRADE from an expression
> into a statement; i.e.
>
> #define SvUPGRADE(sv, mt) (SvTYPE(sv) >= (mt) || (sv_upgrade(sv, mt), 1))
>
> becomes
>
> #define SvUPGRADE(sv, mt) if (sv->type >= (mt)) { sv_upgrade(sv, mt); }
>
> A search for 'if.*SvUPGRADE' on grep.cpan.me indicates that about 15
> distributions would fail to compile and need fixing.
>
> I'm open to other suggestions.
>
>
--
H.Merijn Brand http://tux.nl Perl Monger http://amsterdam.pm.org/
using perl5.00307 .. 5.17 porting perl5 on HP-UX, AIX, and openSUSE
http://mirrors.develooper.com/hpux/ http://www.test-smoke.org/
http://qa.perl.org http://www.goldmark.org/jeff/stupid-disclaimers/
Thread Previous