Skip to content

Commit 35f9925

Browse files
authored
removed usage of emptyString from error messages (#7251)
these can be considered cold paths in the optimal case i.e. no errors
1 parent 90c464e commit 35f9925

9 files changed

+14
-15
lines changed

Diff for: lib/checkclass.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -2038,7 +2038,7 @@ void CheckClass::virtualDestructor()
20382038
}
20392039

20402040
for (const Function *func : inconclusiveErrors)
2041-
virtualDestructorError(func->tokenDef, func->name(), emptyString, true);
2041+
virtualDestructorError(func->tokenDef, func->name(), "", true);
20422042
}
20432043

20442044
void CheckClass::virtualDestructorError(const Token *tok, const std::string &Base, const std::string &Derived, bool inconclusive)

Diff for: lib/checkinternal.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ void CheckInternal::checkRedundantTokCheck()
126126
void CheckInternal::checkRedundantTokCheckError(const Token* tok)
127127
{
128128
reportError(tok, Severity::style, "redundantTokCheck",
129-
"Unnecessary check of \"" + (tok? tok->expressionString(): emptyString) + "\", match-function already checks if it is null.");
129+
"Unnecessary check of \"" + (tok? tok->expressionString(): "") + "\", match-function already checks if it is null.");
130130
}
131131

132132
void CheckInternal::checkTokenSimpleMatchPatterns()

Diff for: lib/checkother.cpp

+5-6
Original file line numberDiff line numberDiff line change
@@ -3512,7 +3512,7 @@ void CheckOther::unusedLabelError(const Token* tok, bool inSwitch, bool hasIfdef
35123512
if (hasIfdef)
35133513
id += "Configuration";
35143514

3515-
std::string msg = "$symbol:" + (tok ? tok->str() : emptyString) + "\nLabel '$symbol' is not used.";
3515+
std::string msg = "$symbol:" + (tok ? tok->str() : "") + "\nLabel '$symbol' is not used.";
35163516
if (hasIfdef)
35173517
msg += " There is #if in function body so the label might be used in code that is removed by the preprocessor.";
35183518
if (inSwitch)
@@ -4325,7 +4325,7 @@ void CheckOther::checkOverlappingWrite()
43254325
constexpr bool follow = true;
43264326
if (!isSameExpression(macro, ptr1, ptr2, *mSettings, pure, follow, &errorPath))
43274327
continue;
4328-
overlappingWriteFunction(tok);
4328+
overlappingWriteFunction(tok, tok->str());
43294329
}
43304330
continue;
43314331
}
@@ -4351,7 +4351,7 @@ void CheckOther::checkOverlappingWrite()
43514351
constexpr bool follow = true;
43524352
if (!isSameExpression(macro, buf1, buf2, *mSettings, pure, follow, &errorPath))
43534353
continue;
4354-
overlappingWriteFunction(tok);
4354+
overlappingWriteFunction(tok, tok->str());
43554355
}
43564356
}
43574357
}
@@ -4362,9 +4362,8 @@ void CheckOther::overlappingWriteUnion(const Token *tok)
43624362
reportError(tok, Severity::error, "overlappingWriteUnion", "Overlapping read/write of union is undefined behavior");
43634363
}
43644364

4365-
void CheckOther::overlappingWriteFunction(const Token *tok)
4365+
void CheckOther::overlappingWriteFunction(const Token *tok, const std::string& funcname)
43664366
{
4367-
const std::string &funcname = tok ? tok->str() : emptyString;
43684367
reportError(tok, Severity::error, "overlappingWriteFunction", "Overlapping read/write in " + funcname + "() is undefined behavior");
43694368
}
43704369

@@ -4430,7 +4429,7 @@ void CheckOther::getErrorMessages(ErrorLogger *errorLogger, const Settings *sett
44304429
c.raceAfterInterlockedDecrementError(nullptr);
44314430
c.invalidFreeError(nullptr, "malloc", false);
44324431
c.overlappingWriteUnion(nullptr);
4433-
c.overlappingWriteFunction(nullptr);
4432+
c.overlappingWriteFunction(nullptr, "funcname");
44344433

44354434
//performance
44364435
c.redundantCopyError(nullptr, "varname");

Diff for: lib/checkother.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ class CPPCHECKLIB CheckOther : public Check {
190190

191191
void checkOverlappingWrite();
192192
void overlappingWriteUnion(const Token *tok);
193-
void overlappingWriteFunction(const Token *tok);
193+
void overlappingWriteFunction(const Token *tok, const std::string& funcname);
194194

195195
// Error messages..
196196
void checkComparisonFunctionIsAlwaysTrueOrFalseError(const Token* tok, const std::string &functionName, const std::string &varName, bool result);

Diff for: lib/checkstl.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -2514,7 +2514,7 @@ void CheckStl::checkDereferenceInvalidIterator2()
25142514
outOfBoundsError(emptyAdvance,
25152515
lValue.tokvalue->expressionString(),
25162516
cValue,
2517-
advanceIndex ? advanceIndex->expressionString() : emptyString,
2517+
advanceIndex ? advanceIndex->expressionString() : "",
25182518
nullptr);
25192519
else
25202520
outOfBoundsError(tok, lValue.tokvalue->expressionString(), cValue, tok->expressionString(), &value);
@@ -3148,7 +3148,7 @@ void CheckStl::knownEmptyContainer()
31483148
const Token* contTok = splitTok->astOperand2();
31493149
if (!isKnownEmptyContainer(contTok))
31503150
continue;
3151-
knownEmptyContainerError(contTok, emptyString);
3151+
knownEmptyContainerError(contTok, "");
31523152
} else {
31533153
const std::vector<const Token *> args = getArguments(tok);
31543154
if (args.empty())

Diff for: lib/checkuninitvar.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -650,7 +650,7 @@ bool CheckUninitVar::checkScopeForVariable(const Token *tok, const Variable& var
650650
// Assert that the tokens are '} while ('
651651
if (!Token::simpleMatch(tok, "} while (")) {
652652
if (printDebug)
653-
reportError(tok,Severity::debug,emptyString,"assertion failed '} while ('");
653+
reportError(tok,Severity::debug,"","assertion failed '} while ('");
654654
break;
655655
}
656656

Diff for: lib/errorlogger.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ class CPPCHECKLIB ErrorMessage {
204204
return mSymbolNames;
205205
}
206206

207-
static ErrorMessage fromInternalError(const InternalError &internalError, const TokenList *tokenList, const std::string &filename, const std::string& msg = emptyString);
207+
static ErrorMessage fromInternalError(const InternalError &internalError, const TokenList *tokenList, const std::string &filename, const std::string& msg = "");
208208

209209
private:
210210
static std::string fixInvalidChars(const std::string& raw);

Diff for: lib/preprocessor.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -878,7 +878,7 @@ void Preprocessor::reportOutput(const simplecpp::OutputList &outputList, bool sh
878878
case simplecpp::Output::EXPLICIT_INCLUDE_NOT_FOUND:
879879
case simplecpp::Output::FILE_NOT_FOUND:
880880
case simplecpp::Output::DUI_ERROR:
881-
error(emptyString, 0, out.msg);
881+
error("", 0, out.msg);
882882
break;
883883
}
884884
}

Diff for: lib/tokenize.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -376,7 +376,7 @@ class CPPCHECKLIB Tokenizer {
376376
public:
377377

378378
/** Syntax error */
379-
NORETURN void syntaxError(const Token *tok, const std::string &code = emptyString) const;
379+
NORETURN void syntaxError(const Token *tok, const std::string &code = "") const;
380380

381381
/** Syntax error. Unmatched character. */
382382
NORETURN void unmatchedToken(const Token *tok) const;

0 commit comments

Comments
 (0)