commit 07afd76b7c3560b53ad1377812a7a5f30696d163
Author: Georg Baum <[email protected]>
Date: Tue Mar 4 23:04:27 2014 +0100
Fix compilation with libc++
libc++ (http://libcxx.llvm.org/) is used on OS X with newer XCode.
The patch is from Benjamin Piwowarski <[email protected]>, 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.
diff --git a/src/Buffer.cpp b/src/Buffer.cpp
index d3aa876..7205f69 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 6edc97b..9490610 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 4d5038d..a4887db 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<typename CharT, typename Traits> class
basic_streambuf;
typedef basic_streambuf<char, char_traits<char> > streambuf;
}
+#endif
namespace lyx {
diff --git a/src/support/strfwd.h b/src/support/strfwd.h
index f1dcb0b..de8588c 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 <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 {
diff --git a/src/tex2lyx/Parser.h b/src/tex2lyx/Parser.h
index 15832f9..67dd0b2 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);