Skip to content

Commit 56e90f9

Browse files
committed
Corrections for non-Microsoft compilers
1 parent 649a89d commit 56e90f9

File tree

6 files changed

+60
-53
lines changed

6 files changed

+60
-53
lines changed

lib/checkcondition.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,7 @@ bool CheckCondition::isOverlappingCond(const Token * const cond1, const Token *
285285
return false;
286286

287287
// same expressions
288-
if (isSameExpression(_tokenizer, cond1,cond2,constFunctions))
288+
if (isSameExpression(_tokenizer, cond1,cond2,constFunctions))
289289
return true;
290290

291291
// bitwise overlap for example 'x&7' and 'x==1'

lib/checkcondition.h

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -95,14 +95,14 @@ class CPPCHECKLIB CheckCondition : public Check {
9595

9696
private:
9797

98-
bool isOverlappingCond(const Token * const cond1, const Token * const cond2, const std::set<std::string> &constFunctions) const;
99-
/**
100-
* Are two conditions opposite
101-
* @param isNot do you want to know if cond1 is !cond2 or if cond1 and cond2 are non-overlapping. true: cond1==!cond2 false: cond1==true => cond2==false
102-
* @param cond1 condition1
103-
* @param cond2 condition2
104-
*/
105-
bool isOppositeCond(bool isNot, const Token * const cond1, const Token * const cond2, const std::set<std::string> &constFunctions) const;
98+
bool isOverlappingCond(const Token * const cond1, const Token * const cond2, const std::set<std::string> &constFunctions) const;
99+
/**
100+
* Are two conditions opposite
101+
* @param isNot do you want to know if cond1 is !cond2 or if cond1 and cond2 are non-overlapping. true: cond1==!cond2 false: cond1==true => cond2==false
102+
* @param cond1 condition1
103+
* @param cond2 condition2
104+
*/
105+
bool isOppositeCond(bool isNot, const Token * const cond1, const Token * const cond2, const std::set<std::string> &constFunctions) const;
106106
void assignIfError(const Token *tok1, const Token *tok2, const std::string &condition, bool result);
107107
void mismatchingBitAndError(const Token *tok1, const MathLib::bigint num1, const Token *tok2, const MathLib::bigint num2);
108108
void badBitmaskCheckError(const Token *tok);

lib/checkother.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -83,12 +83,12 @@ bool isSameExpression(const Tokenizer *tokenizer, const Token *tok1, const Token
8383
return true;
8484
if (tok1 == nullptr || tok2 == nullptr)
8585
return false;
86-
if (tokenizer->isCPP()) {
87-
if (tok1->str() == "." && tok1->astOperand1() && tok1->astOperand1()->str() == "this")
88-
tok1 = tok1->astOperand2();
89-
if (tok2->str() == "." && tok2->astOperand1() && tok2->astOperand1()->str() == "this")
90-
tok2 = tok2->astOperand2();
91-
}
86+
if (tokenizer->isCPP()) {
87+
if (tok1->str() == "." && tok1->astOperand1() && tok1->astOperand1()->str() == "this")
88+
tok1 = tok1->astOperand2();
89+
if (tok2->str() == "." && tok2->astOperand1() && tok2->astOperand1()->str() == "this")
90+
tok2 = tok2->astOperand2();
91+
}
9292
if (tok1->varId() != tok2->varId() || tok1->str() != tok2->str()) {
9393
if ((Token::Match(tok1,"<|>") && Token::Match(tok2,"<|>")) ||
9494
(Token::Match(tok1,"<=|>=") && Token::Match(tok2,"<=|>="))) {
@@ -197,13 +197,13 @@ void CheckOther::checkCastIntToCharAndBack()
197197
if (var && var->typeEndToken()->str() == "char" && !var->typeEndToken()->isSigned()) {
198198
checkCastIntToCharAndBackError(tok, tok->strAt(2));
199199
}
200-
} else if (_tokenizer->isCPP() && Token::Match(tok, "EOF %comp% ( %var% = std :: cin . get (") || Token::Match(tok, "EOF %comp% ( %var% = cin . get (")) {
200+
} else if (_tokenizer->isCPP() && (Token::Match(tok, "EOF %comp% ( %var% = std :: cin . get (") || Token::Match(tok, "EOF %comp% ( %var% = cin . get ("))) {
201201
tok = tok->tokAt(3);
202202
const Variable *var = tok->variable();
203203
if (var && var->typeEndToken()->str() == "char" && !var->typeEndToken()->isSigned()) {
204204
checkCastIntToCharAndBackError(tok, "cin.get");
205205
}
206-
} else if (_tokenizer->isCPP() && Token::Match(tok, "%var% = std :: cin . get (") || Token::Match(tok, "%var% = cin . get (")) {
206+
} else if (_tokenizer->isCPP() && (Token::Match(tok, "%var% = std :: cin . get (") || Token::Match(tok, "%var% = cin . get ("))) {
207207
const Variable *var = tok->variable();
208208
if (var && var->typeEndToken()->str() == "char" && !var->typeEndToken()->isSigned()) {
209209
vars[tok->varId()] = "cin.get";

test/testmathlib.cpp

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -264,11 +264,11 @@ class TestMathLib : public TestFixture {
264264
ASSERT_EQUALS(-1 , MathLib::toLongNumber("-10.E-1"));
265265
ASSERT_EQUALS(100 , MathLib::toLongNumber("+10.0E+1"));
266266
ASSERT_EQUALS(-1 , MathLib::toLongNumber("-10.0E-1"));
267-
268-
ASSERT_EQUALS(-8552249625308161526, MathLib::toLongNumber("0x89504e470d0a1a0a"));
269-
ASSERT_EQUALS(-8481036456200365558, MathLib::toLongNumber("0x8a4d4e470d0a1a0a"));
270-
ASSERT_EQUALS(9894494448401390090, MathLib::toULongNumber("0x89504e470d0a1a0a"));
271-
ASSERT_EQUALS(9965707617509186058, MathLib::toULongNumber("0x8a4d4e470d0a1a0a"));
267+
268+
ASSERT_EQUALS(-8552249625308161526, MathLib::toLongNumber("0x89504e470d0a1a0a"));
269+
ASSERT_EQUALS(-8481036456200365558, MathLib::toLongNumber("0x8a4d4e470d0a1a0a"));
270+
ASSERT_EQUALS(9894494448401390090ULL, MathLib::toULongNumber("0x89504e470d0a1a0a"));
271+
ASSERT_EQUALS(9965707617509186058ULL, MathLib::toULongNumber("0x8a4d4e470d0a1a0a"));
272272

273273
// zero input
274274
ASSERT_EQUALS(0 , MathLib::toULongNumber("0"));
@@ -286,7 +286,12 @@ class TestMathLib : public TestFixture {
286286
ASSERT_EQUALS(5U, MathLib::toULongNumber("0b101"));
287287

288288
// from long long
289-
ASSERT_EQUALS(0xFF00000000000000LL, MathLib::toLongNumber("0xFF00000000000000LL"));
289+
/*
290+
* ASSERT_EQUALS(0xFF00000000000000LL, MathLib::toLongNumber("0xFF00000000000000LL"));
291+
* This does not work in a portable way!
292+
* While it succeds on 32bit Visual Studio it fails on Linux 64bit because it is greater than 0x7FFFFFFFFFFFFFFF (=LLONG_MAX)
293+
*/
294+
290295
ASSERT_EQUALS(0x0A00000000000000LL, MathLib::toLongNumber("0x0A00000000000000LL"));
291296

292297
// -----------------

test/testsuite.cpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,24 @@ void TestFixture::_assertEquals(const char *filename, unsigned int linenr, const
156156
}
157157
}
158158

159+
template<>
160+
void TestFixture::assertEquals(const char *filename, unsigned int linenr, const char expected[], const std::string& actual, const std::string &msg) const
161+
{
162+
assertEquals(filename, linenr, std::string(expected), actual, msg);
163+
}
164+
165+
template<>
166+
void TestFixture::assertEquals(const char *filename, unsigned int linenr, const char expected[], const char actual[], const std::string &msg) const
167+
{
168+
assertEquals(filename, linenr, std::string(expected), std::string(actual), msg);
169+
}
170+
171+
template<>
172+
void TestFixture::assertEquals(const char *filename, unsigned int linenr, const std::string& expected, const char actual[], const std::string &msg) const
173+
{
174+
assertEquals(filename, linenr, expected, std::string(actual), msg);
175+
}
176+
159177
void TestFixture::assertEqualsDouble(const char *filename, unsigned int linenr, double expected, double actual, const std::string &msg) const
160178
{
161179
assertEquals(filename, linenr, MathLib::toString(expected), MathLib::toString(actual), msg);

test/testsuite.h

Lines changed: 14 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -51,36 +51,13 @@ class TestFixture : public ErrorLogger {
5151

5252
void assert_(const char *filename, unsigned int linenr, bool condition) const;
5353
void todoAssert(const char *filename, unsigned int linenr, bool condition) const;
54-
void _assertEquals(const char *filename, unsigned int linenr, const std::string &expected, const std::string &actual, const std::string &msg) const;
55-
56-
template <typename E, typename A>
57-
void assertEquals(const char *filename, unsigned int linenr, const E expected, const A actual, const std::string &msg = emptyString) const {
58-
_assertEquals(filename, linenr, MathLib::toString(expected), MathLib::toString(actual), msg);
59-
}
60-
61-
template<>
62-
void assertEquals(const char *filename, unsigned int linenr, const char expected[], const std::string& actual, const std::string &msg) const
63-
{
64-
assertEquals(filename, linenr, std::string(expected), actual, msg);
65-
}
66-
template<>
67-
void assertEquals(const char *filename, unsigned int linenr, const char expected[], const char actual[], const std::string &msg) const
68-
{
69-
assertEquals(filename, linenr, std::string(expected), std::string(actual), msg);
70-
}
71-
template<>
72-
void assertEquals(const char *filename, unsigned int linenr, const std::string& expected, const char actual[], const std::string &msg) const
73-
{
74-
assertEquals(filename, linenr, expected, std::string(actual), msg);
75-
}
76-
/*
77-
void assertEquals(const char *filename, unsigned int linenr, const std::string &expected, const std::string &actual, const std::string &msg = emptyString) const;
78-
void assertEquals(const char *filename, unsigned int linenr, const char expected[], const std::string& actual, const std::string &msg = emptyString) const;
79-
void assertEquals(const char *filename, unsigned int linenr, const char expected[], const char actual[], const std::string &msg = emptyString) const;
80-
void assertEquals(const char *filename, unsigned int linenr, const std::string& expected, const char actual[], const std::string &msg = emptyString) const;
81-
void assertEquals(const char *filename, unsigned int linenr, long long expected, long long actual, const std::string &msg = emptyString) const;
82-
void assertEquals(const char *filename, unsigned int linenr, unsigned long long expected, unsigned long long actual, const std::string &msg = emptyString) const;
83-
*/
54+
void _assertEquals(const char *filename, unsigned int linenr, const std::string &expected, const std::string &actual, const std::string &msg) const;
55+
56+
template <typename E, typename A>
57+
void assertEquals(const char *filename, unsigned int linenr, const E expected, const A actual, const std::string &msg = emptyString) const {
58+
_assertEquals(filename, linenr, MathLib::toString(expected), MathLib::toString(actual), msg);
59+
}
60+
8461
void assertEqualsDouble(const char *filename, unsigned int linenr, double expected, double actual, const std::string &msg = emptyString) const;
8562

8663
void todoAssertEquals(const char *filename, unsigned int linenr, const std::string &wanted,
@@ -104,6 +81,13 @@ class TestFixture : public ErrorLogger {
10481
static std::size_t runTests(const options& args);
10582
};
10683

84+
template<>
85+
void TestFixture::assertEquals(const char *filename, unsigned int linenr, const char expected[], const std::string& actual, const std::string &msg) const;
86+
template<>
87+
void TestFixture::assertEquals(const char *filename, unsigned int linenr, const char expected[], const char actual[], const std::string &msg) const;
88+
template<>
89+
void TestFixture::assertEquals(const char *filename, unsigned int linenr, const std::string& expected, const char actual[], const std::string &msg) const;
90+
10791
extern std::ostringstream errout;
10892
extern std::ostringstream output;
10993
extern std::ostringstream warnings;

0 commit comments

Comments
 (0)