diff options
-rw-r--r-- | config_host/config_global.h.in | 5 | ||||
-rw-r--r-- | configure.ac | 22 | ||||
-rw-r--r-- | include/o3tl/sorted_vector.hxx | 4 | ||||
-rw-r--r-- | sc/source/core/tool/token.cxx | 3 |
4 files changed, 32 insertions, 2 deletions
diff --git a/config_host/config_global.h.in b/config_host/config_global.h.in index 2e986fbe24b6..adb36c39ab8b 100644 --- a/config_host/config_global.h.in +++ b/config_host/config_global.h.in @@ -24,6 +24,11 @@ Any change in this header will cause a rebuild of almost everything. /* Guaranteed copy elision (C++17), __cpp_guaranteed_copy_elision (C++2a): */ #define HAVE_CPP_GUARANTEED_COPY_ELISION 0 +// Compiler supports all of C++2a <https://wg21.link/P0202R3> "Add Constexpr Modifiers to Functions +// in <algorithm> and <utility> Headers", <https://wg21.link/P1004R2> "Making std::vector +// constexpr", and <https://wg21.link/P1143R2> "Adding the constinit keyword": +#define HAVE_CPP_CONSTINIT_SORTED_VECTOR 0 + /* GCC bug <https://gcc.gnu.org/bugzilla/show_bug.cgi?id=87150> "move ctor wrongly chosen in return stmt (derived vs. base)": */ #define HAVE_GCC_BUG_87150 0 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 diff --git a/include/o3tl/sorted_vector.hxx b/include/o3tl/sorted_vector.hxx index 527f34e568c7..102287d52a21 100644 --- a/include/o3tl/sorted_vector.hxx +++ b/include/o3tl/sorted_vector.hxx @@ -45,10 +45,10 @@ public: typedef typename std::vector<Value>::difference_type difference_type; typedef typename std::vector<Value>::size_type size_type; - sorted_vector( std::initializer_list<Value> init ) + constexpr sorted_vector( std::initializer_list<Value> init ) : m_vector(init) { - Resort(); + std::sort(m_vector.begin(), m_vector.end(), Compare()); } sorted_vector() = default; sorted_vector(sorted_vector const&) = default; diff --git a/sc/source/core/tool/token.cxx b/sc/source/core/tool/token.cxx index b9048dd25f19..475fcf16d189 100644 --- a/sc/source/core/tool/token.cxx +++ b/sc/source/core/tool/token.cxx @@ -1277,6 +1277,9 @@ bool ScTokenArray::AddFormulaToken( void ScTokenArray::CheckForThreading( const FormulaToken& r ) { +#if HAVE_CPP_CONSTINIT_SORTED_VECTOR + constinit +#endif static const o3tl::sorted_vector<OpCode> aThreadedCalcBlackList({ ocIndirect, ocMacro, |