Le 19/05/2015 11:45, Jean-Marc Lasgouttes a écrit :
Le 19/05/2015 11:25, Jean-Marc Lasgouttes a écrit :
Hi Georg,
It is not possible currently to compile with gcc 4.6 in C++11 mode
because lyxalgo.h declares its own next() method. This is because the
code depends on __cplusplus >= 201103L, which is not true for this
version of the compiler.
Georg, would the following commit suit you? With it, I am able to
compile with gcc 4.6 in C++11 mode.
Note that there remain some tests against __cplusplus that should
probably be removed.
JMarc
>From 332a422b8ef498c70add24ee64a18fb4120794f7 Mon Sep 17 00:00:00 2001
From: Jean-Marc Lasgouttes <lasgout...@lyx.org>
Date: Tue, 19 May 2015 15:10:38 +0200
Subject: [PATCH] Use explicit macro to declare that we want to use C++11
This replaces tests for __cplusplus >= 201103L, which are wrong with gcc 4.6 and earlier. Indeed these versions of gcc define __cplusplus = 1.
Reference:
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=1773
---
config/lyxinclude.m4 | 19 ++++++++++++-------
src/support/bind.h | 2 +-
src/support/functional.h | 2 +-
src/support/lyxalgo.h | 4 ++--
src/support/regex.h | 2 +-
src/support/shared_ptr.h | 2 +-
6 files changed, 18 insertions(+), 13 deletions(-)
diff --git a/config/lyxinclude.m4 b/config/lyxinclude.m4
index c9cb11d..ba5344a 100644
--- a/config/lyxinclude.m4
+++ b/config/lyxinclude.m4
@@ -159,6 +159,15 @@ AC_DEFUN([LYX_LIB_STDCXX],
])
+dnl Usage: LYX_CXX_USE_CXX11(STD): pass option -std=STD to the C++ compiler
+dnl and define LYX_USE_CXX11.
+AC_DEFUN([LYX_CXX_USE_CXX11],
+[lyx_flags="$lyx_flags c++11-mode"
+ AM_CXXFLAGS="$AM_CXXFLAGS -std=$1"
+ AC_DEFINE([LYX_USE_CXX11], 1, [Define if LyX should use C++11 features])
+])
+
+
dnl Usage: LYX_LIB_STDCXX_CXX11_ABI: set lyx_cv_lib_stdcxx_cxx11_abi to yes
dnl if the STL library is GNU libstdc++ and the C++11 ABI is used.
AC_DEFUN([LYX_LIB_STDCXX_CXX11_ABI],
@@ -329,17 +338,13 @@ if test x$GXX = xyes; then
case $gxx_version in
4.0*|4.1*|4.2*) AC_ERROR([There is no C++11 support in gcc 4.2 or older]);;
4.3*|4.4*|4.5*|4.6*)
- lyx_flags="$lyx_flags c++11-mode"
- AM_CXXFLAGS="$AM_CXXFLAGS -std=gnu++0x";;
+ LYX_CXX_USE_CXX11(gnu++0x);;
clang)
dnl presumably all clang version support c++11.
- lyx_flags="$lyx_flags c++11-mode"
dnl the deprecated-register warning is very annoying with Qt4.x right now.
- AM_CXXFLAGS="$AM_CXXFLAGS -std=c++11 -Wno-deprecated-register";;
+ LYX_CXX_USE_CXX11(c++11 -Wno-deprecated-register);;
*)
- lyx_flags="$lyx_flags c++11-mode"
- AM_CXXFLAGS="$AM_CXXFLAGS -std=gnu++11"
- ;;
+ LYX_CXX_USE_CXX11(gnu++11);;
esac
if test x$CLANG = xno || test $lyx_cv_lib_stdcxx = yes; then
dnl <regex> in gcc is unusable in versions less than 4.9.0
diff --git a/src/support/bind.h b/src/support/bind.h
index 08dd71a..1449c43 100644
--- a/src/support/bind.h
+++ b/src/support/bind.h
@@ -14,7 +14,7 @@
#include "support/functional.h"
-#if __cplusplus >= 201103L
+#ifdef LYX_USE_CXX11
#define LYX_BIND_NS std
diff --git a/src/support/functional.h b/src/support/functional.h
index b86551d..5d373d1 100644
--- a/src/support/functional.h
+++ b/src/support/functional.h
@@ -12,7 +12,7 @@
#ifndef LYX_FUNCTIONAL_H
#define LYX_FUNCTIONAL_H
-#if __cplusplus >= 201103L
+#ifdef LYX_USE_CXX11
#include <functional>
#define LYX_FUNCTIONAL_NS std
diff --git a/src/support/lyxalgo.h b/src/support/lyxalgo.h
index 410bf75..9e44838 100644
--- a/src/support/lyxalgo.h
+++ b/src/support/lyxalgo.h
@@ -84,7 +84,7 @@ void eliminate_duplicates(C & c)
}
-#if __cplusplus >= 201103L
+#ifdef LYX_USE_CXX11
using std::next;
#else
/// Replacement of std::next for older compilers
@@ -97,7 +97,7 @@ inline It next(It i, Diff n = 1)
#endif
-#if __cplusplus >= 201103L
+#ifdef LYX_USE_CXX11
using std::prev;
#else
/// Replacement of std::prev for older compilers
diff --git a/src/support/regex.h b/src/support/regex.h
index 7c64caf..dd4875e 100644
--- a/src/support/regex.h
+++ b/src/support/regex.h
@@ -12,7 +12,7 @@
#ifndef LYX_REGEXP_H
#define LYX_REGEXP_H
-#if __cplusplus >= 201103L && defined(LYX_USE_STD_REGEX)
+#if defined(LYX_USE_CXX11) && defined(LYX_USE_STD_REGEX)
# include <regex>
# ifdef _MSC_VER
namespace lyx {
diff --git a/src/support/shared_ptr.h b/src/support/shared_ptr.h
index 04dfc50..d011597 100644
--- a/src/support/shared_ptr.h
+++ b/src/support/shared_ptr.h
@@ -12,7 +12,7 @@
#ifndef LYX_SHARED_PTR_H
#define LYX_SHARED_PTR_H
-#if __cplusplus >= 201103L
+#ifdef LYX_USE_CXX11
#include <memory>
#define LYX_SHAREDPTR_NS std
--
1.7.9.5