diff --git a/CMakeLists.txt b/CMakeLists.txt index 5d8497cbecea856af25a853ce399fe69ec0d63ed..7be418bede5135d4a7f6bc5be80fe8b6855b7913 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -8,7 +8,10 @@ enable_language(CXX) set(SAVED_CXX_FLAGS "${CMAKE_CXX_FLAGS}") # compilation flags -set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g -std=c++11 -pthread -Wall") +set(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake") +include("CompilerOptions") +set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${CXXOPT_DEBUG} ${CXXOPT_CXX11} ${CXXOPT_PTHREAD} ${CXXOPT_WALL}") +# -g -std=c++11 -pthread -Wall") # this generates a .json file with full compilation command for each file set(CMAKE_EXPORT_COMPILE_COMMANDS "YES") diff --git a/cmake/CompilerOptions.cmake b/cmake/CompilerOptions.cmake new file mode 100644 index 0000000000000000000000000000000000000000..e5447d88e7d0009f8ec697bb1463e3a7b737b0d8 --- /dev/null +++ b/cmake/CompilerOptions.cmake @@ -0,0 +1,14 @@ +# Compiler-aware compiler options + +set(CXXOPT_DEBUG "-g") +set(CXXOPT_PTHREAD "-pthread") +set(CXXOPT_CXX11 "-std=c++11") +set(CXXOPT_WALL "-Wall") + +if(${CMAKE_CXX_COMPILER_ID} MATCHES "Clang") + # Disable 'missing-braces' warning: this will inappropriately + # flag initializations such as + # std::array<int,3> a={1,2,3}; + + set(CXXOPT_WALL "${CXXOPT_WALL} -Wno-missing-braces") +endif() diff --git a/src/util/optional.hpp b/src/util/optional.hpp index f1fb805bfb86062f1c7c603befd5f01d54fad5f2..a3c2da998d468c8564894f2db61b0340c056c70c 100644 --- a/src/util/optional.hpp +++ b/src/util/optional.hpp @@ -107,7 +107,7 @@ namespace detail { template <typename Y> bool operator==(const optional<Y> &o) const { - return set && o.set && ref()==o.ref() || !set && !o.set; + return (set && o.set && ref()==o.ref()) || (!set && !o.set); } void reset() { diff --git a/tests/test_optional.cpp b/tests/test_optional.cpp index e3ca5ecbbd7466c7f5e7b6a9c2f7bcbef43dd5b1..4fe6301085b69c6fb2efcb7e7685306b8e8c3071 100644 --- a/tests/test_optional.cpp +++ b/tests/test_optional.cpp @@ -5,6 +5,11 @@ #include "gtest.h" #include "util/optional.hpp" +#if defined(__clang__) +// refer: https://llvm.org/bugs/show_bug.cgi?id=21629 +//#pragma clang diagnostic ignored "-Wmissing-braces" +#endif + using namespace nest::mc::util; TEST(optionalm,ctors) { @@ -61,7 +66,7 @@ TEST(optionalm,deref) { TEST(optionalm,ctor_conv) { optional<std::array<int,3>> x{{1,2,3}}; - EXPECT_EQ(3,x->size()); + EXPECT_EQ(3u,x->size()); } TEST(optionalm,ctor_ref) { diff --git a/tests/util.hpp b/tests/util.hpp index 6252c7e439b334342c14b17285418a0e1f7a1c63..cfa89896af8039e6188d8fbc460f412d3407a1b3 100644 --- a/tests/util.hpp +++ b/tests/util.hpp @@ -60,7 +60,7 @@ nlohmann::json load_spike_data(const std::string& input_name) { nlohmann::json cell_data; - auto fid = std::ifstream(input_name); + std::ifstream fid(input_name); if(!fid.is_open()) { std::cerr << "error : unable to open file " << input_name << " : run the validation generation script first\n";