From 89eb36095d63e6046e902cb97968c45d9939675f Mon Sep 17 00:00:00 2001 From: Wu Tao Date: Tue, 28 May 2019 14:04:27 +0800 Subject: [PATCH] use c++14 mode for compilation (#257) --- .travis.yml | 9 +++++---- bin/dsn.cmake | 18 ++++++++++-------- src/core/core/fail_point.cpp | 10 +++++----- src/core/tests/CMakeLists.txt | 2 +- 4 files changed, 21 insertions(+), 18 deletions(-) diff --git a/.travis.yml b/.travis.yml index f829556457..2489de0577 100644 --- a/.travis.yml +++ b/.travis.yml @@ -14,8 +14,12 @@ cache: addons: apt: + update: true + sources: + - ubuntu-toolchain-r-test packages: - clang-format-3.9 + - g++-5 before_install: - wget https://raw.githubusercontent.com/xiaomi/pegasus-common/master/build-depends.tar.gz @@ -25,9 +29,6 @@ before_install: - ls | xargs sudo dpkg -i --force-depends - cd .. -install: - # - ./run.sh format - before_script: - cd thirdparty - wget https://raw.githubusercontent.com/xiaomi/pegasus-common/master/pegasus-thirdparty-prebuild.tar.gz @@ -37,7 +38,7 @@ before_script: - ulimit -c unlimited -S script: - - ./run.sh test --skip_thirdparty --check --disable_gperf + - ./run.sh test --compiler "gcc-5,g++-5" --skip_thirdparty --check --disable_gperf after_script: - ./run.sh stop_zk diff --git a/bin/dsn.cmake b/bin/dsn.cmake index 9f4cf51c08..bd0008b1aa 100644 --- a/bin/dsn.cmake +++ b/bin/dsn.cmake @@ -209,10 +209,18 @@ function(dsn_setup_compiler_flags) # We want access to the PRI* print format macros. add_definitions(-D__STDC_FORMAT_MACROS) + include(CheckCXXCompilerFlag) + CHECK_CXX_COMPILER_FLAG("-std=c++14" COMPILER_SUPPORTS_CXX14) + if(COMPILER_SUPPORTS_CXX14) + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++14" CACHE STRING "" FORCE) + else() + message(FATAL_ERROR "You need a compiler with C++14 support.") + endif() + # -fno-omit-frame-pointer # use frame pointers to allow simple stack frame walking for backtraces. # This has a small perf hit but worth it for the ability to profile in production - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++1y -fno-omit-frame-pointer" CACHE STRING "" FORCE) + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-omit-frame-pointer" CACHE STRING "" FORCE) # -Wall: Enable all warnings. add_compile_options(-Wall) @@ -336,14 +344,8 @@ function(dsn_common_setup) set(BUILD_SHARED_LIBS OFF) - include(CheckCXXCompilerFlag) - CHECK_CXX_COMPILER_FLAG("-std=c++1y" COMPILER_SUPPORTS_CXX1Y) - if(NOT ${COMPILER_SUPPORTS_CXX1Y}) - message(FATAL_ERROR "You need a compiler with C++1y support.") - endif() - dsn_setup_system_libs() dsn_setup_compiler_flags() dsn_setup_include_path() dsn_setup_link_path() -endfunction(dsn_common_setup) \ No newline at end of file +endfunction(dsn_common_setup) diff --git a/src/core/core/fail_point.cpp b/src/core/core/fail_point.cpp index b7698b63df..d80976df1b 100644 --- a/src/core/core/fail_point.cpp +++ b/src/core/core/fail_point.cpp @@ -18,7 +18,7 @@ #include "fail_point_impl.h" #include -#include +#include #include namespace dsn { @@ -57,13 +57,13 @@ bool fail_point::parse_from_string(string_view action) _max_cnt = -1; _freq = 100; - boost::regex regex(R"((\d+\%)?(\d+\*)?(\w+)(\((.*)\))?)"); - boost::smatch match; + std::regex regex(R"((\d+\%)?(\d+\*)?(\w+)(\((.*)\))?)"); + std::smatch match; std::string tmp(action.data(), action.length()); - if (boost::regex_match(tmp, match, regex)) { + if (std::regex_match(tmp, match, regex)) { if (match.size() == 6) { - boost::ssub_match sub_match = match[1]; + std::ssub_match sub_match = match[1]; if (!sub_match.str().empty()) { sscanf(sub_match.str().data(), "%d%%", &_freq); } diff --git a/src/core/tests/CMakeLists.txt b/src/core/tests/CMakeLists.txt index 33b784e3d8..2635e1c947 100644 --- a/src/core/tests/CMakeLists.txt +++ b/src/core/tests/CMakeLists.txt @@ -10,7 +10,7 @@ set(MY_PROJ_INC_PATH ../core ../tools/common ../tools/simulator ../tools/hpc ../tools/nfs ) -set(MY_BOOST_PACKAGES system filesystem regex) +set(MY_BOOST_PACKAGES system filesystem) set(MY_PROJ_LIBS gtest dsn_runtime