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

SvUPGRADE and void

Thread Next
Dave Mitchell
December 13, 2012 19:49
SvUPGRADE and void
Message ID:
SvUPGRADE() generates lots of 'warning: expression result unused' clang

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.

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))


#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.

"Strange women lying in ponds distributing swords is no basis for a system
of government. Supreme executive power derives from a mandate from the
masses, not from some farcical aquatic ceremony."
    -- Dennis, "Monty Python and the Holy Grail"

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