This following patch improves the autotools detection of std::regex. It
fixes several issues there and makes code more readable IMO.
Georg, I'd like to have your review on this, especially since my
previous commit e1938aa2 on the subject was a bit buggy.
Tested with gcc 4.3, gcc 5.1, gcc 4.8, clang 3.7 + libc++
There is still a potential problem that I cannot test because my system
is too new: when clang is used with a stdlibc++ from gcc 4.8 or older, I
suspect that we will use the bad regex.
I do not know how to handle that since in this case libstdc++ will not
giv us any version number we can rely on. Anyway, the patch here does
not make matters worse in this regard.
JMarc
>From 5189f5dfdbae142175f2adff191557c3126a9be4 Mon Sep 17 00:00:00 2001
From: Jean-Marc Lasgouttes <lasgout...@lyx.org>
Date: Wed, 6 Jan 2016 10:33:54 +0100
Subject: [PATCH 1/2] Fix the logic of selection of std::regex
This amends commit e1938aa2, which introduced some logic
errors: regex would be enabled for gcc versions which have unusable
<regex> header.
The new code separates better special gcc handling from special C++11
handling and should be more readable.
* set -std=c++11 in AM_CPPFLAGS instead of AM_CXXFLAGS, since the
preprocessor uses this setting too.
* Before checking for header <regex>, set language to C++ and update
value of AM_CPPFLAGS too.
* Separate code that checks for regex in its own macro.
* now unknown compiler which have the <regex> header, will use std::regex in C++11 mode.
---
config/lyxinclude.m4 | 84 ++++++++++++++++++++++++++++++++--------------------
1 file changed, 52 insertions(+), 32 deletions(-)
diff --git a/config/lyxinclude.m4 b/config/lyxinclude.m4
index 5c8ff6c..81e91ca 100644
--- a/config/lyxinclude.m4
+++ b/config/lyxinclude.m4
@@ -151,7 +151,9 @@ dnl the C++11 standard.
AC_DEFUN([LYX_CXX_CXX11],
[AC_CACHE_CHECK([whether the compiler implements C++11],
[lyx_cv_cxx_cxx11],
- [save_CXXFLAGS=$CXXFLAGS
+ [save_CPPFLAGS=$CPPFLAGS
+ CPPFLAGS="$AM_CPPFLAGS $CPPFLAGS"
+ save_CXXFLAGS=$CXXFLAGS
CXXFLAGS="$AM_CXXFLAGS $CXXFLAGS"
AC_LANG_PUSH(C++)
AC_TRY_COMPILE([], [
@@ -161,8 +163,44 @@ AC_DEFUN([LYX_CXX_CXX11],
],
[lyx_cv_cxx_cxx11=no], [lyx_cv_cxx_cxx11=yes ; lyx_flags="$lyx_flags c++11"])
AC_LANG_POP(C++)
- CXXFLAGS=$save_CXXFLAGS])
-lyx_use_cxx11=$lyx_cv_cxx_cxx11
+ CXXFLAGS=$save_CXXFLAGS
+ CPPFLAGS=$save_CPPFLAGS])
+ lyx_use_cxx11=$lyx_cv_cxx_cxx11
+])
+
+dnl decide whether we want to use std::regex and set the
+dnl LYX_USE_STD_REGEX accordingly.
+AC_DEFUN([LYX_CXX_USE_REGEX],
+[lyx_std_regex=no
+ if test $lyx_use_cxx11 = yes; then
+ save_CPPFLAGS=$CPPFLAGS
+ CPPFLAGS="$AM_CPPFLAGS $CPPFLAGS"
+ save_CXXFLAGS=$CXXFLAGS
+ CXXFLAGS="$AM_CXXFLAGS $CXXFLAGS"
+ AC_LANG_PUSH(C++)
+ AC_CHECK_HEADER([regex], [lyx_std_regex=yes], [lyx_std_regex=no])
+ AC_LANG_POP(C++)
+ CXXFLAGS=$save_CXXFLAGS
+ CPPFLAGS=$save_CPPFLAGS
+ if test x$GXX = xyes && test $lyx_std_regex = yes ; then
+ AC_MSG_CHECKING([for correct regex implementation])
+ 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
+ dnl see https://gcc.gnu.org/bugzilla/show_bug.cgi?id=53631
+ case $gxx_version in
+ 4.0*|4.1*|4.2*|4.3*|4.4*|4.5*|4.6*|4.7*|4.8*) lyx_std_regex=no ;;
+ *) ;;
+ esac
+ fi
+ fi
+ AC_MSG_RESULT([$lyx_std_regex])
+ fi
+
+ if test $lyx_std_regex = yes ; then
+ lyx_flags="$lyx_flags std-regex"
+ AC_DEFINE([LYX_USE_STD_REGEX], 1, [define to 1 if std::regex should be preferred to boost::regex])
+ fi
+ AM_CONDITIONAL([LYX_USE_STD_REGEX], test $lyx_std_regex = yes)
])
@@ -270,7 +308,6 @@ if test "x$enable_assertions" = xyes ; then
fi
# set the compiler options correctly.
-lyx_std_regex=no
if test x$GXX = xyes; then
dnl clang++ pretends to be g++ 4.2.1; this is not useful
if test x$CLANG = xno; then
@@ -325,46 +362,29 @@ if test x$GXX = xyes; then
4.3*|4.4*|4.5*|4.6*)
dnl Note that this will define __GXX_EXPERIMENTAL_CXX0X__.
dnl The source code relies on that.
- AM_CXXFLAGS="$AM_CXXFLAGS -std=c++0x";;
+ AM_CPPFLAGS="$AM_CPPFLAGS -std=c++0x";;
clang)
dnl presumably all clang versions support c++11.
dnl the deprecated-register warning is very annoying with Qt4.x right now.
- AM_CXXFLAGS="$AM_CXXFLAGS -std=c++11 -Wno-deprecated-register";;
+ AM_CPPFLAGS="$AM_CPPFLAGS -std=c++11"
+ AM_CXXFLAGS="$AM_CXXFLAGS -Wno-deprecated-register";;
*)
AS_CASE([$host], [*cygwin*],
- [AM_CXXFLAGS="$AM_CXXFLAGS -std=gnu++11"],
- [AM_CXXFLAGS="$AM_CXXFLAGS -std=c++11"]);;
+ [AM_CPPFLAGS="$AM_CPPFLAGS -std=gnu++11"],
+ [AM_CPPFLAGS="$AM_CPPFLAGS -std=c++11"]);;
esac
fi
+fi
- LYX_CXX_CXX11
- if test $lyx_use_cxx11 = yes ; then
+LYX_CXX_CXX11
+if test $lyx_use_cxx11 = yes; then
+ if test x$GXX = xyes; then
dnl We still use auto_ptr, which is obsoleted. Shut off the warnings.
AM_CXXFLAGS="$AM_CXXFLAGS -Wno-deprecated-declarations"
-
- AC_CHECK_HEADER([regex], [lyx_std_regex=yes], [lyx_std_regex=no])
- 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
- dnl see https://gcc.gnu.org/bugzilla/show_bug.cgi?id=53631
- case $gxx_version in
- 4.0*|4.1*|4.2*|4.3*|4.4*|4.5*|4.6*|4.7*|4.8*) ;;
- *) lyx_std_regex=yes ;;
- esac
- else
- lyx_std_regex=yes
- fi
fi
-else
- dnl This is not gcc, not sure what setup we can do
- AC_CHECK_HEADER([regex], [lyx_std_regex=yes], [lyx_std_regex=no])
-fi
-
-if test $lyx_std_regex = yes ; then
- lyx_flags="$lyx_flags stdregex"
- AC_DEFINE([LYX_USE_STD_REGEX], 1, [define to 1 if std::regex should be preferred to boost::regex])
fi
-AM_CONDITIONAL([LYX_USE_STD_REGEX], test $lyx_std_regex = yes)
-])dnl
+LYX_CXX_USE_REGEX
+])
dnl Usage: LYX_USE_INCLUDED_BOOST : select if the included boost should
dnl be used.
--
2.5.0