Hi.

I'm getting compiler warnings for narrowing conversions when I write a cpp_int to a stream.

This is with boost 1_53_0 on OS X 10.8.3 using Xcode version 4.6.2 with clang:

/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang --version
Apple LLVM version 4.2 (clang-425.0.28) (based on LLVM 3.2svn)
Target: x86_64-apple-darwin12.3.0
Thread model: posix

Here's a short example causing the problem:

//
//  main.cpp
//

#include <boost/multiprecision/cpp_int.hpp>
#include <iostream>

int main(int argc, const char * argv[])
{
using namespace boost::multiprecision;
cpp_int u = 1;
for(unsigned i = 1; i <= 100; ++i)
u *= i;


std::cout << "100! using arbitrary precision cpp_int:\n";
std::cout << u << std::endl; // prints 100!

    return 0;
}

The short compiler messages:

In file included from /Users/olea/code/mjaal/learn/boost/build/xcode/mp_warner/mp_warner/main.cpp:5:
/usr/local/include/boost/multiprecision/cpp_int.hpp:1573:34: warning: implicit conversion loses integer precision: 'unsigned long' to 'int' [-Wshorten-64-to-32]
         int pos = result.size() - 1;
             ~~~   ~~~~~~~~~~~~~~^~~
/usr/local/include/boost/multiprecision/cpp_int.hpp:1653:14: note: in instantiation of member function 'boost::multiprecision::backends::cpp_int_backend<0, 0, 1, 0, std::__1::allocator<unsigned int> >::do_get_string' requested here
      return do_get_string(f, trivial_tag());
             ^
/usr/local/include/boost/multiprecision/number.hpp:576:24: note: in instantiation of member function 'boost::multiprecision::backends::cpp_int_backend<0, 0, 1, 0, std::__1::allocator<unsigned int> >::str' requested here
      return m_backend.str(digits, f);
                       ^
/usr/local/include/boost/multiprecision/number.hpp:1650:22: note: in instantiation of member function 'boost::multiprecision::number<boost::multiprecision::backends::cpp_int_backend<0, 0, 1, 0, std::__1::allocator<unsigned int> >, 1>::str' requested here
   std::string s = r.str(d, os.flags());
                     ^
/Users/olea/code/mjaal/learn/boost/build/xcode/mp_warner/mp_warner/main.cpp:16:12: note: in instantiation of function template specialization 'boost::multiprecision::operator<<<boost::multiprecision::backends::cpp_int_backend<0, 0, 1, 0, std::__1::allocator<unsigned int> >, 1>' requested here
        std::cout << u << std::endl; // prints 100!
                  ^
In file included from /Users/olea/code/mjaal/learn/boost/build/xcode/mp_warner/mp_warner/main.cpp:5:
/usr/local/include/boost/multiprecision/cpp_int.hpp:1606:34: warning: implicit conversion loses integer precision: 'unsigned long' to 'int' [-Wshorten-64-to-32]
         int pos = result.size() - 1;
             ~~~   ~~~~~~~~~~~~~~^~~
/usr/local/include/boost/multiprecision/cpp_int.hpp:1639:23: warning: implicit conversion loses integer precision: 'size_type' (aka 'unsigned long') to 'unsigned int' [-Wshorten-64-to-32]
         unsigned n = result.find_first_not_of('0');
                  ~   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
3 warnings generated.

The compile command:

CompileC /Users/olea/Library/Developer/Xcode/DerivedData/mp_warner-fvjhjlwtkmsewtfsdqsuzhczhlxd/Build/Intermediates/mp_warner.build/Debug/mp_warner.build/Objects-normal/x86_64/main.o mp_warner/main.cpp normal x86_64 c++ com.apple.compilers.llvm.clang.1_0.compiler
    cd /Users/olea/code/mjaal/learn/boost/build/xcode/mp_warner
    setenv LANG en_US.US-ASCII
    /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang -x c++ -arch x86_64 -fmessage-length=0 -std=gnu++11 -stdlib=libc++ -Wno-trigraphs -fpascal-strings -O0 -Wno-missing-field-initializers -Wno-missing-prototypes -Wreturn-type -Wno-non-virtual-dtor -Wno-overloaded-virtual -Wno-exit-time-destructors -Wformat -Wno-missing-braces -Wparentheses -Wswitch -Wno-unused-function -Wno-unused-label -Wno-unused-parameter -Wunused-variable -Wunused-value -Wempty-body -Wuninitialized -Wno-unknown-pragmas -Wno-shadow -Wno-four-char-constants -Wno-conversion -Wconstant-conversion -Wint-conversion -Wenum-conversion -Wshorten-64-to-32 -Wno-newline-eof -Wno-c++11-extensions -DDEBUG=1 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.8.sdk -fasm-blocks -fstrict-aliasing -Wdeprecated-declarations -Winvalid-offsetof -mmacosx-version-min=10.8 -g -fvisibility-inlines-hidden -Wno-sign-conversion -iquote /Users/olea/Library/Developer/Xcode/DerivedData/mp_warner-fvjhjlwtkmsewtfsdqsuzhczhlxd/Build/Intermediates/mp_warner.build/Debug/mp_warner.build/mp_warner-generated-files.hmap -I/Users/olea/Library/Developer/Xcode/DerivedData/mp_warner-fvjhjlwtkmsewtfsdqsuzhczhlxd/Build/Intermediates/mp_warner.build/Debug/mp_warner.build/mp_warner-own-target-headers.hmap -I/Users/olea/Library/Developer/Xcode/DerivedData/mp_warner-fvjhjlwtkmsewtfsdqsuzhczhlxd/Build/Intermediates/mp_warner.build/Debug/mp_warner.build/mp_warner-all-target-headers.hmap -iquote /Users/olea/Library/Developer/Xcode/DerivedData/mp_warner-fvjhjlwtkmsewtfsdqsuzhczhlxd/Build/Intermediates/mp_warner.build/Debug/mp_warner.build/mp_warner-project-headers.hmap -I/Users/olea/Library/Developer/Xcode/DerivedData/mp_warner-fvjhjlwtkmsewtfsdqsuzhczhlxd/Build/Products/Debug/include -I/usr/local/include -I/Users/olea/Library/Developer/Xcode/DerivedData/mp_warner-fvjhjlwtkmsewtfsdqsuzhczhlxd/Build/Intermediates/mp_warner.build/Debug/mp_warner.build/DerivedSources/x86_64 -I/Users/olea/Library/Developer/Xcode/DerivedData/mp_warner-fvjhjlwtkmsewtfsdqsuzhczhlxd/Build/Intermediates/mp_warner.build/Debug/mp_warner.build/DerivedSources -F/Users/olea/Library/Developer/Xcode/DerivedData/mp_warner-fvjhjlwtkmsewtfsdqsuzhczhlxd/Build/Products/Debug -MMD -MT dependencies -MF /Users/olea/Library/Developer/Xcode/DerivedData/mp_warner-fvjhjlwtkmsewtfsdqsuzhczhlxd/Build/Intermediates/mp_warner.build/Debug/mp_warner.build/Objects-normal/x86_64/main.d --serialize-diagnostics /Users/olea/Library/Developer/Xcode/DerivedData/mp_warner-fvjhjlwtkmsewtfsdqsuzhczhlxd/Build/Intermediates/mp_warner.build/Debug/mp_warner.build/Objects-normal/x86_64/main.dia -c /Users/olea/code/mjaal/learn/boost/build/xcode/mp_warner/mp_warner/main.cpp -o /Users/olea/Library/Developer/Xcode/DerivedData/mp_warner-fvjhjlwtkmsewtfsdqsuzhczhlxd/Build/Intermediates/mp_warner.build/Debug/mp_warner.build/Objects-normal/x86_64/main.o