[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [lmi] Fixing 64-bit GNU/Linux gcc-4.x issues

From: Vadim Zeitlin
Subject: Re: [lmi] Fixing 64-bit GNU/Linux gcc-4.x issues
Date: Wed, 14 Nov 2007 16:27:02 +0100

On Wed, 14 Nov 2007 03:53:12 +0000 Greg Chicares <address@hidden> wrote:

GC> Vadim--You reported three issues, and I believe I've fixed two of
GC> them already:
GC> (1) 20071114T0313Z ChangeLog: I don't know how we missed changing
GC> this cast as part of the similar change on 20070401T1429Z.
GC> (2) 20071114T0315Z ChangeLog: wxUSE_STL no longer required.


GC> The third issue is this g++-4.2.1 warning
GC>   actuarial_table.cpp:74: warning: negative integer implicitly converted to 
unsigned type
GC> stemming from this line
GC>         T const invalid(-1);
GC> in a function template instantiated with an unsigned type such as
GC> 'unsigned char'. I'm working on an msw system with gcc-3.4.4; the
GC> gcc-4.x that I have is unstable, and I'd rather avoid building
GC> everything with it right now, so could I ask you to try something
GC> like the following technique used in 'tn_range.tpp'?
GC>     /// Signum, defined here to return 0 for NaNs.
GC>     ///
GC>     /// To handle unsigned types without warnings, the value zero is
GC>     /// stored in a volatile variable, and the value negative one is
GC>     /// cast to the argument type.
GC>     template<typename T>
GC>     T signum(T t)
GC>     {
GC>     ...
GC>         T volatile zero = 0;
GC>         if(t < zero)
GC>             {
GC>             return static_cast<T>(-1);
GC>             }

 This doesn't really lend itself well to the code in read_datum() as it
initializes t with -1 first and then compares it with it. But in fact
fixing the warning is as simple as adding a static_cast:

Index: actuarial_table.cpp
RCS file: /sources/lmi/lmi/actuarial_table.cpp,v
retrieving revision 1.34
diff -u -2 -r1.34 actuarial_table.cpp
--- actuarial_table.cpp 14 Oct 2007 23:50:52 -0000      1.34
+++ actuarial_table.cpp 14 Nov 2007 15:25:34 -0000
@@ -72,5 +72,5 @@
         LMI_ASSERT(sizeof(T) == nominal_length);
         // The value -1 is invalid for all integral data fields.
-        T const invalid(-1);
+        T const invalid(static_cast<T>(-1));
         t = invalid;
         char z[sizeof(T)];

Do you see anything wrong with doing this?


reply via email to

[Prev in Thread] Current Thread [Next in Thread]