[Boost-bugs] [Boost C++ Libraries] #6852: lexical_cast: warning: ISO C++ does not support the ‘%lg’ gnu_printf format

Subject: [Boost-bugs] [Boost C++ Libraries] #6852: lexical_cast: warning: ISO C++ does not support the ‘%lg’ gnu_printf format
From: Boost C++ Libraries (noreply_at_[hidden])
Date: 2012-05-01 17:54:57


#6852: lexical_cast: warning: ISO C++ does not support the ‘%lg’ gnu_printf format
-------------------------------+--------------------------------------------
 Reporter: peter@… | Owner: apolukhin
     Type: Bugs | Status: new
Milestone: To Be Determined | Component: lexical_cast
  Version: Boost 1.49.0 | Severity: Cosmetic
 Keywords: |
-------------------------------+--------------------------------------------
 The following code produces a warning if compiled with GCC (4.7.0) and
 -Wall -std=c++98 -pedantic:

 {{{
 include <boost/lexical_cast.hpp>

 int main()
 {
     boost::lexical_cast<std::string>(double(4.2));
     return 0;
 }
 }}}

 {{{
 boost_1_49_0/include/boost/lexical_cast.hpp:1297:17: warning: ISO C++ does
 not support the ‘%lg’ gnu_printf format [-Wformat]
 }}}


 With regard to the length modifier, the printf(3) man page (RHEL 6.2)
 states:
 {{{
        l (ell) A following integer conversion corresponds to a long
 int
               or unsigned long int argument, or a following n conversion
 cor-
               responds to a pointer to a long int argument, or a
 following c
               conversion corresponds to a wint_t argument, or a
 following s
               conversion corresponds to a pointer to wchar_t argument.
 }}}

 With regard to the conversion specifier:
 {{{
        g, G The double argument is converted in style f or e (or F or E
 for
               G conversions). The precision specifies the number of
 signifi-
               cant digits. If the precision is missing, 6 digits are
 given;
               if the precision is zero, it is treated as 1. Style e is
 used
               if the exponent from its conversion is less than -4 or
 greater
               than or equal to the precision. Trailing zeros are removed
 from
               the fractional part of the result; a decimal point appears
 only
               if it is followed by at least one digit.
 }}}

 So the correct printf format for double is "%g".

 (Maybe this is different on non-GNU systems?)

-- 
Ticket URL: <https://svn.boost.org/trac/boost/ticket/6852>
Boost C++ Libraries <http://www.boost.org/>
Boost provides free peer-reviewed portable C++ source libraries.

This archive was generated by hypermail 2.1.7 : 2017-02-16 18:50:09 UTC