summaryrefslogtreecommitdiff
path: root/configure.ac
diff options
context:
space:
mode:
authorStephan Bergmann <sbergman@redhat.com>2019-09-25 14:43:16 +0200
committerStephan Bergmann <sbergman@redhat.com>2019-09-25 20:55:53 +0200
commit689dc632875c4ec51e44cf53718d625d9a217d9c (patch)
tree90a01344b3a678b114a7f8038005ae75062a2e71 /configure.ac
parent52b3333ff592b10b9b628863e7b06506b2106568 (diff)
constinit, here we come
Following up on b13421011d9377676e1adc282634991d5064a866 "better data structures for some static const vars": * Make the o3tl::sorted_vector ctor taking an initializer_list constexpr. <https://wg21.link/P0202R3> "Add Constexpr Modifiers to Functions in <algorithm> and <utility> Headers", which will be in C++2a and is already implemented by recent libc++ and libstdc++ according to <https://en.cppreference.com/w/cpp/compiler_support #C.2B.2B2a_library_features>, makes std::sort constexpr but explicitly keeps std::stable_sort non-constexpr. ("Algorithms stable_partition, inplace_merge and stable_sort allocate memory, construct variables using placement new, use unique_ptr and do other things not acceptable in constexpr expressions. Making those algorithms constexpr seems to be a hard task that would require a lot of intrinsics. Those algorithms are not marked with constexpr in this wording.") But keep o3tl::sorted_vector::Resort (which was introduced in c59355e936446fe55960209e543b072acb6b2170 "fdo#58793: re-implement SwpHintsArray::Resort()") using std::stable_sort instead of std::sort, in case that is relevant for its pre-exisiting uses. * <https://wg21.link/P1004R2> "Making std::vector constexpr", which was voted into C++2a according to <https://wg21.link/n4829> "Editors' Report -- Programming Languages -- C++", will make the relevant parts of std::vector constexpr. But none of libc++, libstdc++, and MSVC implement that as of now. * Introduce HAVE_CPP_CONSTINIT_SORTED_VECTOR to hide the constinit behind for now for the one case from b13421011d9377676e1adc282634991d5064a866 "better data structures for some static const vars" that can clearly be constinit once constexpr std::vector is supported by compilers. The other three cases (s_aContainerDocumentCommands in chart2/source/controller/main/CommandDispatchContainer.cxx, aMetricCompatibleMap in vcl/source/font/PhysicalFontCollection.cxx, and aBlacklist in writerfilter/source/dmapper/PropertyMap.cxx) would each need a constexpr OUString first. (Technically, the constinit would not even be needed, but it nicely documents our intent that this will actually be initialized at compile-time once compilers support that.) Change-Id: Ibeb138f120528be3a7a09b3912143bf795fbab29 Reviewed-on: https://gerrit.libreoffice.org/79556 Tested-by: Jenkins Reviewed-by: Stephan Bergmann <sbergman@redhat.com>
Diffstat (limited to 'configure.ac')
-rw-r--r--configure.ac22
1 files changed, 22 insertions, 0 deletions
diff --git a/configure.ac b/configure.ac
index 88c512c2635f..eb08a5883eda 100644
--- a/configure.ac
+++ b/configure.ac
@@ -6618,6 +6618,28 @@ AC_COMPILE_IFELSE([AC_LANG_SOURCE([
CXXFLAGS=$save_CXXFLAGS
AC_LANG_POP([C++])
+AC_MSG_CHECKING([whether $CXX_BASE supports C++2a constinit sorted vectors])
+AC_LANG_PUSH([C++])
+save_CXXFLAGS=$CXXFLAGS
+CXXFLAGS="$CXXFLAGS $CXXFLAGS_CXX11"
+AC_COMPILE_IFELSE([AC_LANG_SOURCE([
+ #include <algorithm>
+ #include <initializer_list>
+ #include <vector>
+ template<typename T> class S {
+ private:
+ std::vector<T> v_;
+ public:
+ constexpr S(std::initializer_list<T> i): v_(i) { std::sort(v_.begin(), v_.end()); }
+ };
+ constinit S<int> s{3, 2, 1};
+ ])], [
+ AC_DEFINE([HAVE_CPP_CONSTINIT_SORTED_VECTOR],[1])
+ AC_MSG_RESULT([yes])
+ ], [AC_MSG_RESULT([no])])
+CXXFLAGS=$save_CXXFLAGS
+AC_LANG_POP([C++])
+
AC_MSG_CHECKING([whether $CXX_BASE has GCC bug 87150])
AC_LANG_PUSH([C++])
save_CXXFLAGS=$CXXFLAGS