further fix to SvUPGRADE
authorDavid Mitchell <davem@iabyn.com>
Fri, 14 Dec 2012 21:28:02 +0000 (21:28 +0000)
committerDavid Mitchell <davem@iabyn.com>
Fri, 14 Dec 2012 23:01:16 +0000 (23:01 +0000)
The change to SvUPGRADE introduced by 463ea2290a54e a few commits ago
to silence a warning with clang, broke g++ builds instead. Here's
a second attempt to keep everyone happy.

Basically it avoids warnings from all of gcc, g++ and clang for the two
constructs

    SvUPGRADE(...);
    (void)SvUPGRADE(...);

But still breaks

    if (!SvUPGRADE(...) { croak(...); }

which I don't care about.

sv.h

diff --git a/sv.h b/sv.h
index c017454..e248ba7 100644 (file)
--- a/sv.h
+++ b/sv.h
@@ -327,8 +327,10 @@ perform the upgrade if necessary.  See C<svtype>.
    them all by using a consistent macro.  */
 #define SvIS_FREED(sv) ((sv)->sv_flags == SVTYPEMASK)
 
+/* this is defined in this peculiar way to avoid compiler warnings.
+ * See the <20121213131428.GD1842@iabyn.com> thread in p5p */
 #define SvUPGRADE(sv, mt) \
-        STMT_START { if (SvTYPE(sv) < (mt)) sv_upgrade(sv, mt); } STMT_END
+    ((void)(SvTYPE(sv) >= (mt) || (sv_upgrade(sv, mt),1)))
 
 #define SVf_IOK                0x00000100  /* has valid public integer value */
 #define SVf_NOK                0x00000200  /* has valid public numeric value */