diff --git a/cmake/compileroptions.cmake b/cmake/compileroptions.cmake index 74256f5ab..e7d0a3bf7 100644 --- a/cmake/compileroptions.cmake +++ b/cmake/compileroptions.cmake @@ -73,14 +73,11 @@ elseif (CMAKE_CXX_COMPILER_ID MATCHES "Clang") add_link_options(-lc++) endif() - add_compile_options_safe(-Wno-documentation-unknown-command) - # TODO: fix and enable these warnings - or move to suppression list below + add_compile_options_safe(-Wno-documentation-unknown-command) # TODO: Clang currently does not support all commands add_compile_options_safe(-Wno-inconsistent-missing-destructor-override) # caused by Qt moc code add_compile_options_safe(-Wno-unused-exception-parameter) add_compile_options_safe(-Wno-old-style-cast) - add_compile_options_safe(-Wno-global-constructors) - add_compile_options_safe(-Wno-exit-time-destructors) add_compile_options_safe(-Wno-sign-conversion) add_compile_options_safe(-Wno-shadow-field-in-constructor) add_compile_options_safe(-Wno-covered-switch-default) @@ -102,16 +99,26 @@ elseif (CMAKE_CXX_COMPILER_ID MATCHES "Clang") add_compile_options_safe(-Wno-tautological-type-limit-compare) add_compile_options(-Wno-disabled-macro-expansion) add_compile_options_safe(-Wno-bitwise-instead-of-logical) - add_compile_options_safe(-Wno-unsafe-buffer-usage) - # warnings we are not interested in - add_compile_options(-Wno-four-char-constants) - add_compile_options(-Wno-c++98-compat) - add_compile_options(-Wno-weak-vtables) + # these cannot be fixed properly without adopting later C++ standards + add_compile_options_safe(-Wno-unsafe-buffer-usage) + add_compile_options_safe(-Wno-global-constructors) + add_compile_options_safe(-Wno-exit-time-destructors) + + # can only be partially addressed add_compile_options(-Wno-padded) + + # no need for C++98 compatibility + add_compile_options(-Wno-c++98-compat) add_compile_options(-Wno-c++98-compat-pedantic) + + # only need to be addressed to work around issues in older compilers add_compile_options_safe(-Wno-return-std-move-in-c++11) + # warnings we are currently not interested in + add_compile_options(-Wno-four-char-constants) + add_compile_options(-Wno-weak-vtables) + if(ENABLE_COVERAGE OR ENABLE_COVERAGE_XML) message(FATAL_ERROR "Do not use clang to generate code coverage. Use GCC instead.") endif() diff --git a/externals/tinyxml2/CMakeLists.txt b/externals/tinyxml2/CMakeLists.txt index 6ec93e526..6ad63ecf0 100644 --- a/externals/tinyxml2/CMakeLists.txt +++ b/externals/tinyxml2/CMakeLists.txt @@ -17,5 +17,6 @@ if (CMAKE_CXX_COMPILER_ID MATCHES "Clang") target_compile_options_safe(tinyxml2_objs -Wno-suggest-destructor-override) target_compile_options_safe(tinyxml2_objs -Wno-zero-as-null-pointer-constant) target_compile_options_safe(tinyxml2_objs -Wno-format-nonliteral) + target_compile_options_safe(tinyxml2_objs -Wno-old-style-cast) endif() diff --git a/lib/calculate.h b/lib/calculate.h index 3e62e212b..96520cc62 100644 --- a/lib/calculate.h +++ b/lib/calculate.h @@ -36,7 +36,7 @@ inline bool isEqual(double x, double y) } inline bool isEqual(float x, float y) { - return isEqual(double{x}, double{y}); + return isEqual(double(x), double(y)); } template diff --git a/lib/checkcondition.cpp b/lib/checkcondition.cpp index a0799b4b4..477719d3e 100644 --- a/lib/checkcondition.cpp +++ b/lib/checkcondition.cpp @@ -981,7 +981,7 @@ T getvalue3(const T value1, const T value2) template<> double getvalue3(const double value1, const double value2) { - return (value1 + value2) / 2.0f; + return (value1 + value2) / 2.0; } diff --git a/lib/valueflow.cpp b/lib/valueflow.cpp index 3091275a2..b6601ce6b 100644 --- a/lib/valueflow.cpp +++ b/lib/valueflow.cpp @@ -9112,12 +9112,12 @@ static void valueFlowSafeFunctions(TokenList& tokenlist, const SymbolDatabase& s std::list argValues; argValues.emplace_back(0); argValues.back().valueType = ValueFlow::Value::ValueType::FLOAT; - argValues.back().floatValue = isLow ? low : -1E25f; + argValues.back().floatValue = isLow ? low : -1E25; argValues.back().errorPath.emplace_back(arg.nameToken(), "Safe checks: Assuming argument has value " + MathLib::toString(argValues.back().floatValue)); argValues.back().safe = true; argValues.emplace_back(0); argValues.back().valueType = ValueFlow::Value::ValueType::FLOAT; - argValues.back().floatValue = isHigh ? high : 1E25f; + argValues.back().floatValue = isHigh ? high : 1E25; argValues.back().errorPath.emplace_back(arg.nameToken(), "Safe checks: Assuming argument has value " + MathLib::toString(argValues.back().floatValue)); argValues.back().safe = true; valueFlowForward(const_cast(functionScope->bodyStart->next()), diff --git a/test/testvalueflow.cpp b/test/testvalueflow.cpp index 4e3225961..8a50059ef 100644 --- a/test/testvalueflow.cpp +++ b/test/testvalueflow.cpp @@ -349,7 +349,7 @@ private: return false; } - bool testValueOfX_(const char* file, int line, const char code[], unsigned int linenr, float value, float diff) { + bool testValueOfX_(const char* file, int line, const char code[], unsigned int linenr, double value, double diff) { // Tokenize.. Tokenizer tokenizer(&settings, this); std::istringstream istr(code); @@ -565,7 +565,7 @@ private: void valueFlowNumber() { ASSERT_EQUALS(123, valueOfTok("x=123;", "123").intvalue); ASSERT_EQUALS_DOUBLE(192.0, valueOfTok("x=0x0.3p10;", "0x0.3p10").floatValue, 1e-5); // 3 * 16^-1 * 2^10 = 192 - ASSERT(std::fabs(valueOfTok("x=0.5;", "0.5").floatValue - 0.5f) < 0.1f); + ASSERT(std::fabs(valueOfTok("x=0.5;", "0.5").floatValue - 0.5) < 0.1); ASSERT_EQUALS(10, valueOfTok("enum {A=10,B=15}; x=A+0;", "+").intvalue); ASSERT_EQUALS(0, valueOfTok("x=false;", "false").intvalue); ASSERT_EQUALS(1, valueOfTok("x=true;", "true").intvalue); @@ -3491,7 +3491,7 @@ private: void valueFlowForwardCompoundAssign() { const char *code; - code = "void f() {\n" + code = "int f() {\n" " int x = 123;\n" " x += 43;\n" " return x;\n" @@ -3501,19 +3501,26 @@ private: "3,Compound assignment '+=', assigned value is 166\n", getErrorPathForX(code, 4U)); - code = "void f() {\n" + code = "int f() {\n" " int x = 123;\n" " x /= 0;\n" // don't crash when evaluating x/=0 " return x;\n" "}"; ASSERT_EQUALS(false, testValueOfX(code, 4U, 123)); - code = "void f() {\n" - " float x = 123.45;\n" + code = "float f() {\n" + " float x = 123.45f;\n" " x += 67;\n" " return x;\n" "}"; - ASSERT_EQUALS(true, testValueOfX(code, 4U, 123.45F + 67, 0.01F)); + ASSERT_EQUALS(true, testValueOfX(code, 4U, (double)123.45f + 67, 0.01)); + + code = "double f() {\n" + " double x = 123.45;\n" + " x += 67;\n" + " return x;\n" + "}"; + ASSERT_EQUALS(true, testValueOfX(code, 4U, 123.45 + 67, 0.01)); code = "void f() {\n" " int x = 123;\n" @@ -3522,7 +3529,7 @@ private: "}"; ASSERT_EQUALS(true, testValueOfX(code, 4U, 61)); - code = "void f() {\n" + code = "int f() {\n" " int x = 123;\n" " x <<= 1;\n" " return x;\n"