From 07afd76b7c3560b53ad1377812a7a5f30696d163 Mon Sep 17 00:00:00 2001 From: Georg Baum Date: Tue, 4 Mar 2014 23:04:27 +0100 Subject: [PATCH] Fix compilation with libc++ libc++ (http://libcxx.llvm.org/) is used on OS X with newer XCode. The patch is from Benjamin Piwowarski , I only added more comments. The changes regarding implicit conversion to bool of std::iostream work because both the C++98 and C++11 standards guarantee that boolean evaluation of streams returns !fail(). See e.g. http://stackoverflow.com/questions/1334858/why-dont-iostream-objects-overload-operator-bool for details. --- src/Buffer.cpp | 3 ++- src/mathed/MathExtern.cpp | 6 ++++-- src/support/debug.h | 5 +++++ src/support/strfwd.h | 13 +++++++++++++ src/tex2lyx/Parser.h | 6 ++++-- 5 files changed, 28 insertions(+), 5 deletions(-) diff --git a/src/Buffer.cpp b/src/Buffer.cpp index d3aa876e77..7205f69278 100644 --- a/src/Buffer.cpp +++ b/src/Buffer.cpp @@ -994,7 +994,8 @@ bool Buffer::importString(string const & format, docstring const & contents, Err TempFile const tempfile("Buffer_importStringXXXXXX." + fmt->extension()); FileName const name(tempfile.name()); ofdocstream os(name.toFilesystemEncoding().c_str()); - bool const success = (os << contents); + // Do not convert os implicitly to bool, since that is forbidden in C++11. + bool const success = !(os << contents).fail(); os.close(); bool converted = false; diff --git a/src/mathed/MathExtern.cpp b/src/mathed/MathExtern.cpp index 6edc97b107..949061017c 100644 --- a/src/mathed/MathExtern.cpp +++ b/src/mathed/MathExtern.cpp @@ -1472,7 +1472,8 @@ bool extractNumber(MathData const & ar, int & i) { idocstringstream is(charSequence(ar.begin(), ar.end())); is >> i; - return is; + // Do not convert is implicitly to bool, since that is forbidden in C++11. + return !is.fail(); } @@ -1480,7 +1481,8 @@ bool extractNumber(MathData const & ar, double & d) { idocstringstream is(charSequence(ar.begin(), ar.end())); is >> d; - return is; + // Do not convert is implicitly to bool, since that is forbidden in C++11. + return !is.fail(); } diff --git a/src/support/debug.h b/src/support/debug.h index 4d5038de7d..a4887db7ae 100644 --- a/src/support/debug.h +++ b/src/support/debug.h @@ -17,6 +17,10 @@ #include "support/strfwd.h" +// Forward definitions do not work with libc++ +// but ios_base has already been defined in strfwd +// if compiling with it +#ifndef _LIBCPP_VERSION namespace std { class ios_base; @@ -25,6 +29,7 @@ template class basic_streambuf; typedef basic_streambuf > streambuf; } +#endif namespace lyx { diff --git a/src/support/strfwd.h b/src/support/strfwd.h index f1dcb0bca9..de8588cabc 100644 --- a/src/support/strfwd.h +++ b/src/support/strfwd.h @@ -13,6 +13,14 @@ #ifndef STRFWD_H #define STRFWD_H +// This includes does nothing but defining _LIBCPP_VERSION +// if libc++ is used (rather than libstdc++) - we first +// check if we have at least a c++03 standard before +// including the file +#if (__cplusplus > 19971L) +#include +#endif + #ifdef USE_WCHAR_T // Prefer this if possible because GNU libstdc++ has usable @@ -28,6 +36,10 @@ namespace lyx { typedef boost::uint32_t char_type; } #endif +// Forward definitions do not work with libc++ +#ifdef _LIBCPP_VERSION +#include +#else namespace std { @@ -52,6 +64,7 @@ typedef basic_ostringstream, allocator > ostringst } // namepace std +#endif namespace lyx { diff --git a/src/tex2lyx/Parser.h b/src/tex2lyx/Parser.h index 15832f9fa7..67dd0b2457 100644 --- a/src/tex2lyx/Parser.h +++ b/src/tex2lyx/Parser.h @@ -125,8 +125,10 @@ public: iparserdocstream(idocstream & is) : is_(is) {} - /// Like std::istream::operator bool() - operator bool() const { return s_.empty() ? is_ : true; } + /// Like std::istream::operator void*() + /// Do not convert is_ implicitly to bool, since that is forbidden in C++11. + /// FIXME: Convert to operator void*() in LyX 2.2 + operator bool() const { return s_.empty() ? !is_.fail() : true; } /// change the encoding of the input stream to \p e (iconv name) void setEncoding(std::string const & e); -- 2.39.5