lmi
[Top][All Lists]
Advanced

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

Re: [lmi] More enabled warnings, less boost


From: Vadim Zeitlin
Subject: Re: [lmi] More enabled warnings, less boost
Date: Mon, 6 Feb 2017 23:01:06 +0100

On Mon, 6 Feb 2017 20:02:40 +0000 Greg Chicares <address@hidden> wrote:

GC> On 2017-02-06 17:58, Vadim Zeitlin wrote:
GC> > On Mon, 6 Feb 2017 15:35:42 +0000 Greg Chicares <address@hidden> wrote:
GC> > 
GC> [...pragma GCC push, pop, etc. ...]
GC> >
GC> > GC> No, thanks. I already tried those pragmata. I wrote them around
GC> > GC> calls to boost facilities. I wrote them around inclusions of
GC> > GC> boost headers. I still got the same number of lines of compiler
GC> > GC> diagnostics (8932 lines or so). Searching the web, all signs
GC> > GC> point to an open defect on gcc's bugzilla.
GC> > 
GC> >  I couldn't find any bugs related to this, could you please give a link to
GC> > this one?
GC> 
GC> https://gcc.gnu.org/bugzilla/show_bug.cgi?id=53431

 But this seems to be a problem with -Wundef (and other warnings given
during the preprocessing/lexing stages), not -Wconversion.

GC> > GC>     int cents() const
GC> > GC>         {
GC> > GC> //      return cents_ % cents_per_dollar;
GC> > GC>         // C++11 [5.6/4]: "if the quotient a/b is representable in the
GC> > GC>         // type of the result, (a/b)*b + a%b is equal to a"
GC> > GC>         return static_cast<int>(cents_ - (cents_ / cents_per_dollar) 
* cents_per_dollar);
GC> > GC>         }
GC> > 
GC> >  I don't understand how is this preferable to
GC> > 
GC> >   return static_cast<int>(cents_ % cents_per_dollar);
GC> > 
GC> > ?
GC> 
GC> IIRC, with '-Wconversion', gcc flagged "cents_ % cents_per_dollar"
GC> as suspicious in itself because the operands are of different types.

 Hmm, I don't see this here neither with g++ 4.9.2 nor with g++ 6. I do see

currency.hpp: In member function ‘int currency::cents() const’:
currency.hpp:135:25: error: conversion to ‘int’ from ‘long int’ may alter its 
value [-Werror=conversion]
         return cents_ % cents_per_dollar;
                ~~~~~~~^~~~~~~~~~~~~~~~~~

with g++ 6 which seems to imply that the warning is somehow about the
operation itself (with 4.9 the last line contains only "^" and no "~" at
all), but applying
---------------------------------- >8 --------------------------------------
diff --git a/currency.hpp b/currency.hpp
index e8b81b3..bd7b528 100644
--- a/currency.hpp
+++ b/currency.hpp
@@ -132,7 +132,7 @@ class currency

     int cents() const
         {
-        return cents_ % cents_per_dollar;
+        return static_cast<int>(cents_ % cents_per_dollar);
         }

     /// Total number of cents, e.g., 123 for 1 dollar and 23 cents.
---------------------------------- >8 --------------------------------------
fixes this warning (there are 3 other ones, including a -Wfloat-conversion
one which might be a more productive one to enable as it should result in
much fewer false positives than the full -Wconversion, so it still doesn't
compile).

 Regards,
VZ


reply via email to

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