Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 15 additions & 8 deletions cmake/compileroptions.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)

# 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)

# 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)
# 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()
Expand Down
1 change: 1 addition & 0 deletions externals/tinyxml2/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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()

2 changes: 1 addition & 1 deletion lib/calculate.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<class T>
Expand Down
2 changes: 1 addition & 1 deletion lib/checkcondition.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}


Expand Down
4 changes: 2 additions & 2 deletions lib/valueflow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9132,12 +9132,12 @@ static void valueFlowSafeFunctions(TokenList* tokenlist, const SymbolDatabase* s
std::list<ValueFlow::Value> 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<Token*>(functionScope->bodyStart->next()),
Expand Down
23 changes: 15 additions & 8 deletions test/testvalueflow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,7 @@ class TestValueFlow : public TestFixture {
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);
Expand Down Expand Up @@ -565,7 +565,7 @@ class TestValueFlow : public TestFixture {
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);
Expand Down Expand Up @@ -3491,7 +3491,7 @@ class TestValueFlow : public TestFixture {
void valueFlowForwardCompoundAssign() {
const char *code;

code = "void f() {\n"
code = "int f() {\n"
" int x = 123;\n"
" x += 43;\n"
" return x;\n"
Expand All @@ -3501,19 +3501,26 @@ class TestValueFlow : public TestFixture {
"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"
Expand All @@ -3522,7 +3529,7 @@ class TestValueFlow : public TestFixture {
"}";
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"
Expand Down