]> git.lyx.org Git - lyx.git/commitdiff
Fix compilation with libc++
authorGeorg Baum <baum@lyx.org>
Tue, 4 Mar 2014 22:04:27 +0000 (23:04 +0100)
committerGeorg Baum <baum@lyx.org>
Tue, 4 Mar 2014 22:27:57 +0000 (23:27 +0100)
libc++ (http://libcxx.llvm.org/) is used on OS X with newer XCode.
The patch is from Benjamin Piwowarski <benjamin.piwowarski@lip6.fr>, 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
src/mathed/MathExtern.cpp
src/support/debug.h
src/support/strfwd.h
src/tex2lyx/Parser.h

index d3aa876e770ee731574f5b58eeb9b35991476725..7205f692789a3653e0827183637e6eddc19e6dad 100644 (file)
@@ -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;
index 6edc97b1074289a1d3eb03d197527da0ad310a4b..949061017cd536e2364ec6fd0cdc1702def515fb 100644 (file)
@@ -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();
 }
 
 
index 4d5038de7d25acb7787dda4c874dcd4dbd5d5e37..a4887db7ae72573f07c588f25d4ae13536e904fa 100644 (file)
 
 #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<typename CharT, typename Traits> class basic_streambuf;
 typedef basic_streambuf<char, char_traits<char> > streambuf;
 
 }
+#endif
 
 
 namespace lyx {
index f1dcb0bca925d4b75244a996ad9ce1fbfd7829b8..de8588cabce30c8517d48fb5132bd4d42dc7707a 100644 (file)
 #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 <ciso646>
+#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 <string>
+#else
 
 namespace std {
 
@@ -52,6 +64,7 @@ typedef basic_ostringstream<char, char_traits<char>, allocator<char> > ostringst
 
 } // namepace std
 
+#endif
 
 namespace lyx {
 
index 15832f9fa7d739c3a8c975683c4ae295ad70f9c4..67dd0b2457c297eb76c2181c540b73a071d630f8 100644 (file)
@@ -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);