Skip to content

Commit 4e4997c

Browse files
committed
fixed #13607 - print float values as such in valueflow debug output
1 parent f19ddb1 commit 4e4997c

File tree

5 files changed

+60
-6
lines changed

5 files changed

+60
-6
lines changed

Makefile

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -335,7 +335,8 @@ TESTOBJ = test/fixture.o \
335335
test/testutils.o \
336336
test/testvaarg.o \
337337
test/testvalueflow.o \
338-
test/testvarid.o
338+
test/testvarid.o \
339+
test/testvfvalue.o
339340

340341
.PHONY: run-dmake tags
341342

@@ -900,6 +901,9 @@ test/testvalueflow.o: test/testvalueflow.cpp externals/simplecpp/simplecpp.h lib
900901
test/testvarid.o: test/testvarid.cpp externals/simplecpp/simplecpp.h lib/addoninfo.h lib/check.h lib/checkers.h lib/color.h lib/config.h lib/errorlogger.h lib/errortypes.h lib/library.h lib/mathlib.h lib/platform.h lib/preprocessor.h lib/settings.h lib/standards.h lib/suppressions.h lib/templatesimplifier.h lib/token.h lib/tokenize.h lib/tokenlist.h lib/utils.h lib/vfvalue.h test/fixture.h test/helpers.h
901902
$(CXX) ${INCLUDE_FOR_TEST} $(CPPFLAGS) $(CXXFLAGS) -c -o $@ test/testvarid.cpp
902903

904+
test/testvfvalue.o: test/testvfvalue.cpp lib/addoninfo.h lib/check.h lib/checkers.h lib/color.h lib/config.h lib/errorlogger.h lib/errortypes.h lib/library.h lib/mathlib.h lib/platform.h lib/settings.h lib/standards.h lib/suppressions.h lib/utils.h lib/vfvalue.h test/fixture.h
905+
$(CXX) ${INCLUDE_FOR_TEST} $(CPPFLAGS) $(CXXFLAGS) -c -o $@ test/testvfvalue.cpp
906+
903907
externals/simplecpp/simplecpp.o: externals/simplecpp/simplecpp.cpp externals/simplecpp/simplecpp.h
904908
$(CXX) $(CPPFLAGS) $(CXXFLAGS) -w -c -o $@ externals/simplecpp/simplecpp.cpp
905909

lib/vfvalue.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#include "vfvalue.h"
2020

2121
#include "errortypes.h"
22+
#include "mathlib.h"
2223
#include "token.h"
2324

2425
#include <sstream>
@@ -58,7 +59,7 @@ namespace ValueFlow {
5859
ss << this->tokvalue->str();
5960
break;
6061
case ValueType::FLOAT:
61-
ss << this->floatValue;
62+
ss << MathLib::toString(this->floatValue);
6263
break;
6364
case ValueType::MOVED:
6465
ss << toString(this->moveKind);

test/cli/other_test.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3072,12 +3072,12 @@ def test_debug_valueflow(tmp_path):
30723072
'##Value flow',
30733073
'File {}'.format(str(test_file).replace('\\', '/')),
30743074
'Line 3',
3075-
' = always 2',
3076-
' 1.0 always 1',
3077-
' / always 2',
3075+
' = always 2.0',
3076+
' 1.0 always 1.0',
3077+
' / always 2.0',
30783078
' 0.5 always 0.5',
30793079
'Line 4',
3080-
' d always {symbolic=(1.0/0.5),2}'
3080+
' d always {symbolic=(1.0/0.5),2.0}'
30813081
]
30823082

30833083

test/testrunner.vcxproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@
111111
<ClCompile Include="testvaarg.cpp" />
112112
<ClCompile Include="testvalueflow.cpp" />
113113
<ClCompile Include="testvarid.cpp" />
114+
<ClCompile Include="testvfvalue.cpp" />
114115
</ItemGroup>
115116
<ItemGroup Label="HeaderFiles">
116117
<ClInclude Include="..\cli\cmdlineparser.h" />

test/testvfvalue.cpp

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
/*
2+
* Cppcheck - A tool for static C/C++ code analysis
3+
* Copyright (C) 2007-2024 Cppcheck team.
4+
*
5+
* This program is free software: you can redistribute it and/or modify
6+
* it under the terms of the GNU General Public License as published by
7+
* the Free Software Foundation, either version 3 of the License, or
8+
* (at your option) any later version.
9+
*
10+
* This program is distributed in the hope that it will be useful,
11+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
* GNU General Public License for more details.
14+
*
15+
* You should have received a copy of the GNU General Public License
16+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
17+
*/
18+
19+
#include "fixture.h"
20+
#include "vfvalue.h"
21+
22+
class TestValueFlowValue : public TestFixture {
23+
public:
24+
TestValueFlowValue() : TestFixture("TestValueFlowValue") {}
25+
26+
private:
27+
void run() override {
28+
TEST_CASE(toString);
29+
}
30+
31+
void toString() const {
32+
{
33+
ValueFlow::Value v;
34+
ASSERT_EQUALS("0", v.toString());
35+
v.intvalue = -1;
36+
ASSERT_EQUALS("-1", v.toString());
37+
}
38+
{
39+
ValueFlow::Value v;
40+
v.valueType = ValueFlow::Value::ValueType::FLOAT;
41+
ASSERT_EQUALS("0.0", v.toString());
42+
v.floatValue = 0.0000000000001;
43+
ASSERT_EQUALS("1e-13", v.toString());
44+
}
45+
}
46+
};
47+
48+
REGISTER_TEST(TestValueFlowValue)

0 commit comments

Comments
 (0)