Skip to content

Commit dcdf67a

Browse files
authored
some -Wdouble-promotion Clang compiler warnings (#4820)
1 parent cc592a6 commit dcdf67a

6 files changed

Lines changed: 35 additions & 20 deletions

File tree

cmake/compileroptions.cmake

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -73,14 +73,11 @@ elseif (CMAKE_CXX_COMPILER_ID MATCHES "Clang")
7373
add_link_options(-lc++)
7474
endif()
7575

76-
add_compile_options_safe(-Wno-documentation-unknown-command)
77-
7876
# TODO: fix and enable these warnings - or move to suppression list below
77+
add_compile_options_safe(-Wno-documentation-unknown-command) # TODO: Clang currently does not support all commands
7978
add_compile_options_safe(-Wno-inconsistent-missing-destructor-override) # caused by Qt moc code
8079
add_compile_options_safe(-Wno-unused-exception-parameter)
8180
add_compile_options_safe(-Wno-old-style-cast)
82-
add_compile_options_safe(-Wno-global-constructors)
83-
add_compile_options_safe(-Wno-exit-time-destructors)
8481
add_compile_options_safe(-Wno-sign-conversion)
8582
add_compile_options_safe(-Wno-shadow-field-in-constructor)
8683
add_compile_options_safe(-Wno-covered-switch-default)
@@ -102,16 +99,26 @@ elseif (CMAKE_CXX_COMPILER_ID MATCHES "Clang")
10299
add_compile_options_safe(-Wno-tautological-type-limit-compare)
103100
add_compile_options(-Wno-disabled-macro-expansion)
104101
add_compile_options_safe(-Wno-bitwise-instead-of-logical)
102+
103+
# these cannot be fixed properly without adopting later C++ standards
105104
add_compile_options_safe(-Wno-unsafe-buffer-usage)
105+
add_compile_options_safe(-Wno-global-constructors)
106+
add_compile_options_safe(-Wno-exit-time-destructors)
106107

107-
# warnings we are not interested in
108-
add_compile_options(-Wno-four-char-constants)
109-
add_compile_options(-Wno-c++98-compat)
110-
add_compile_options(-Wno-weak-vtables)
108+
# can only be partially addressed
111109
add_compile_options(-Wno-padded)
110+
111+
# no need for C++98 compatibility
112+
add_compile_options(-Wno-c++98-compat)
112113
add_compile_options(-Wno-c++98-compat-pedantic)
114+
115+
# only need to be addressed to work around issues in older compilers
113116
add_compile_options_safe(-Wno-return-std-move-in-c++11)
114117

118+
# warnings we are currently not interested in
119+
add_compile_options(-Wno-four-char-constants)
120+
add_compile_options(-Wno-weak-vtables)
121+
115122
if(ENABLE_COVERAGE OR ENABLE_COVERAGE_XML)
116123
message(FATAL_ERROR "Do not use clang to generate code coverage. Use GCC instead.")
117124
endif()

externals/tinyxml2/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,6 @@ if (CMAKE_CXX_COMPILER_ID MATCHES "Clang")
1717
target_compile_options_safe(tinyxml2_objs -Wno-suggest-destructor-override)
1818
target_compile_options_safe(tinyxml2_objs -Wno-zero-as-null-pointer-constant)
1919
target_compile_options_safe(tinyxml2_objs -Wno-format-nonliteral)
20+
target_compile_options_safe(tinyxml2_objs -Wno-old-style-cast)
2021
endif()
2122

lib/calculate.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ inline bool isEqual(double x, double y)
3636
}
3737
inline bool isEqual(float x, float y)
3838
{
39-
return isEqual(double{x}, double{y});
39+
return isEqual(double(x), double(y));
4040
}
4141

4242
template<class T>

lib/checkcondition.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -981,7 +981,7 @@ T getvalue3(const T value1, const T value2)
981981
template<>
982982
double getvalue3(const double value1, const double value2)
983983
{
984-
return (value1 + value2) / 2.0f;
984+
return (value1 + value2) / 2.0;
985985
}
986986

987987

lib/valueflow.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9112,12 +9112,12 @@ static void valueFlowSafeFunctions(TokenList& tokenlist, const SymbolDatabase& s
91129112
std::list<ValueFlow::Value> argValues;
91139113
argValues.emplace_back(0);
91149114
argValues.back().valueType = ValueFlow::Value::ValueType::FLOAT;
9115-
argValues.back().floatValue = isLow ? low : -1E25f;
9115+
argValues.back().floatValue = isLow ? low : -1E25;
91169116
argValues.back().errorPath.emplace_back(arg.nameToken(), "Safe checks: Assuming argument has value " + MathLib::toString(argValues.back().floatValue));
91179117
argValues.back().safe = true;
91189118
argValues.emplace_back(0);
91199119
argValues.back().valueType = ValueFlow::Value::ValueType::FLOAT;
9120-
argValues.back().floatValue = isHigh ? high : 1E25f;
9120+
argValues.back().floatValue = isHigh ? high : 1E25;
91219121
argValues.back().errorPath.emplace_back(arg.nameToken(), "Safe checks: Assuming argument has value " + MathLib::toString(argValues.back().floatValue));
91229122
argValues.back().safe = true;
91239123
valueFlowForward(const_cast<Token*>(functionScope->bodyStart->next()),

test/testvalueflow.cpp

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -349,7 +349,7 @@ class TestValueFlow : public TestFixture {
349349
return false;
350350
}
351351

352-
bool testValueOfX_(const char* file, int line, const char code[], unsigned int linenr, float value, float diff) {
352+
bool testValueOfX_(const char* file, int line, const char code[], unsigned int linenr, double value, double diff) {
353353
// Tokenize..
354354
Tokenizer tokenizer(&settings, this);
355355
std::istringstream istr(code);
@@ -565,7 +565,7 @@ class TestValueFlow : public TestFixture {
565565
void valueFlowNumber() {
566566
ASSERT_EQUALS(123, valueOfTok("x=123;", "123").intvalue);
567567
ASSERT_EQUALS_DOUBLE(192.0, valueOfTok("x=0x0.3p10;", "0x0.3p10").floatValue, 1e-5); // 3 * 16^-1 * 2^10 = 192
568-
ASSERT(std::fabs(valueOfTok("x=0.5;", "0.5").floatValue - 0.5f) < 0.1f);
568+
ASSERT(std::fabs(valueOfTok("x=0.5;", "0.5").floatValue - 0.5) < 0.1);
569569
ASSERT_EQUALS(10, valueOfTok("enum {A=10,B=15}; x=A+0;", "+").intvalue);
570570
ASSERT_EQUALS(0, valueOfTok("x=false;", "false").intvalue);
571571
ASSERT_EQUALS(1, valueOfTok("x=true;", "true").intvalue);
@@ -3491,7 +3491,7 @@ class TestValueFlow : public TestFixture {
34913491
void valueFlowForwardCompoundAssign() {
34923492
const char *code;
34933493

3494-
code = "void f() {\n"
3494+
code = "int f() {\n"
34953495
" int x = 123;\n"
34963496
" x += 43;\n"
34973497
" return x;\n"
@@ -3501,19 +3501,26 @@ class TestValueFlow : public TestFixture {
35013501
"3,Compound assignment '+=', assigned value is 166\n",
35023502
getErrorPathForX(code, 4U));
35033503

3504-
code = "void f() {\n"
3504+
code = "int f() {\n"
35053505
" int x = 123;\n"
35063506
" x /= 0;\n" // don't crash when evaluating x/=0
35073507
" return x;\n"
35083508
"}";
35093509
ASSERT_EQUALS(false, testValueOfX(code, 4U, 123));
35103510

3511-
code = "void f() {\n"
3512-
" float x = 123.45;\n"
3511+
code = "float f() {\n"
3512+
" float x = 123.45f;\n"
35133513
" x += 67;\n"
35143514
" return x;\n"
35153515
"}";
3516-
ASSERT_EQUALS(true, testValueOfX(code, 4U, 123.45F + 67, 0.01F));
3516+
ASSERT_EQUALS(true, testValueOfX(code, 4U, (double)123.45f + 67, 0.01));
3517+
3518+
code = "double f() {\n"
3519+
" double x = 123.45;\n"
3520+
" x += 67;\n"
3521+
" return x;\n"
3522+
"}";
3523+
ASSERT_EQUALS(true, testValueOfX(code, 4U, 123.45 + 67, 0.01));
35173524

35183525
code = "void f() {\n"
35193526
" int x = 123;\n"
@@ -3522,7 +3529,7 @@ class TestValueFlow : public TestFixture {
35223529
"}";
35233530
ASSERT_EQUALS(true, testValueOfX(code, 4U, 61));
35243531

3525-
code = "void f() {\n"
3532+
code = "int f() {\n"
35263533
" int x = 123;\n"
35273534
" x <<= 1;\n"
35283535
" return x;\n"

0 commit comments

Comments
 (0)