develooper Front page | perl.perl5.porters | Postings from December 2012

Re: SvUPGRADE and void

Thread Previous
H.Merijn Brand
December 14, 2012 07:36
Re: SvUPGRADE and void
Message ID:
On Thu, 13 Dec 2012 13:14:28 +0000, Dave Mitchell <>

> 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, 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 indicates that about 15
> distributions would fail to compile and need fixing.
> I'm open to other suggestions.

H.Merijn Brand   Perl Monger
using perl5.00307 .. 5.17   porting perl5 on HP-UX, AIX, and openSUSE

Thread Previous Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About