Skip to content

Commit 8cc3e0b

Browse files
authored
errortypes.h: use enum class instead of wrapping types into classes (#4693)
1 parent 911d610 commit 8cc3e0b

11 files changed

+28
-34
lines changed

lib/check.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ void Check::reportError(const ErrorMessage &errmsg)
5050
}
5151

5252

53-
void Check::reportError(const std::list<const Token *> &callstack, Severity::SeverityType severity, const std::string &id, const std::string &msg, const CWE &cwe, Certainty::CertaintyLevel certainty)
53+
void Check::reportError(const std::list<const Token *> &callstack, Severity::SeverityType severity, const std::string &id, const std::string &msg, const CWE &cwe, Certainty certainty)
5454
{
5555
const ErrorMessage errmsg(callstack, mTokenizer ? &mTokenizer->list : nullptr, severity, id, msg, cwe, certainty);
5656
if (mErrorLogger)
@@ -59,7 +59,7 @@ void Check::reportError(const std::list<const Token *> &callstack, Severity::Sev
5959
reportError(errmsg);
6060
}
6161

62-
void Check::reportError(const ErrorPath &errorPath, Severity::SeverityType severity, const char id[], const std::string &msg, const CWE &cwe, Certainty::CertaintyLevel certainty)
62+
void Check::reportError(const ErrorPath &errorPath, Severity::SeverityType severity, const char id[], const std::string &msg, const CWE &cwe, Certainty certainty)
6363
{
6464
const ErrorMessage errmsg(errorPath, mTokenizer ? &mTokenizer->list : nullptr, severity, id, msg, cwe, certainty);
6565
if (mErrorLogger)

lib/check.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ class CPPCHECKLIB Check {
140140
}
141141

142142
/** report an error */
143-
void reportError(const Token *tok, const Severity::SeverityType severity, const std::string &id, const std::string &msg, const CWE &cwe, Certainty::CertaintyLevel certainty) {
143+
void reportError(const Token *tok, const Severity::SeverityType severity, const std::string &id, const std::string &msg, const CWE &cwe, Certainty certainty) {
144144
const std::list<const Token *> callstack(1, tok);
145145
reportError(callstack, severity, id, msg, cwe, certainty);
146146
}
@@ -151,9 +151,9 @@ class CPPCHECKLIB Check {
151151
}
152152

153153
/** report an error */
154-
void reportError(const std::list<const Token *> &callstack, Severity::SeverityType severity, const std::string &id, const std::string &msg, const CWE &cwe, Certainty::CertaintyLevel certainty);
154+
void reportError(const std::list<const Token *> &callstack, Severity::SeverityType severity, const std::string &id, const std::string &msg, const CWE &cwe, Certainty certainty);
155155

156-
void reportError(const ErrorPath &errorPath, Severity::SeverityType severity, const char id[], const std::string &msg, const CWE &cwe, Certainty::CertaintyLevel certainty);
156+
void reportError(const ErrorPath &errorPath, Severity::SeverityType severity, const char id[], const std::string &msg, const CWE &cwe, Certainty certainty);
157157

158158
ErrorPath getErrorPath(const Token* errtok, const ValueFlow::Value* value, std::string bug) const;
159159

lib/checkbufferoverrun.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -678,7 +678,7 @@ void CheckBufferOverrun::bufferOverflow()
678678
}
679679
}
680680

681-
void CheckBufferOverrun::bufferOverflowError(const Token *tok, const ValueFlow::Value *value, const Certainty::CertaintyLevel &certainty)
681+
void CheckBufferOverrun::bufferOverflowError(const Token *tok, const ValueFlow::Value *value, Certainty certainty)
682682
{
683683
reportError(getErrorPath(tok, value, "Buffer overrun"), Severity::error, "bufferAccessOutOfBounds", "Buffer is accessed out of bounds: " + (tok ? tok->expressionString() : "buf"), CWE_BUFFER_OVERRUN, certainty);
684684
}

lib/checkbufferoverrun.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ class CPPCHECKLIB CheckBufferOverrun : public Check {
111111
void pointerArithmeticError(const Token *tok, const Token *indexToken, const ValueFlow::Value *indexValue);
112112

113113
void bufferOverflow();
114-
void bufferOverflowError(const Token *tok, const ValueFlow::Value *value, const Certainty::CertaintyLevel& certainty);
114+
void bufferOverflowError(const Token *tok, const ValueFlow::Value *value, Certainty certainty);
115115

116116
void arrayIndexThenCheck();
117117
void arrayIndexThenCheckError(const Token *tok, const std::string &indexName);

lib/errorlogger.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ ErrorMessage::ErrorMessage()
4343
: severity(Severity::none), cwe(0U), certainty(Certainty::normal), hash(0)
4444
{}
4545

46-
ErrorMessage::ErrorMessage(std::list<FileLocation> callStack, std::string file1, Severity::SeverityType severity, const std::string &msg, std::string id, Certainty::CertaintyLevel certainty) :
46+
ErrorMessage::ErrorMessage(std::list<FileLocation> callStack, std::string file1, Severity::SeverityType severity, const std::string &msg, std::string id, Certainty certainty) :
4747
callStack(std::move(callStack)), // locations for this error message
4848
id(std::move(id)), // set the message id
4949
file0(std::move(file1)),
@@ -58,7 +58,7 @@ ErrorMessage::ErrorMessage(std::list<FileLocation> callStack, std::string file1,
5858

5959

6060

61-
ErrorMessage::ErrorMessage(std::list<FileLocation> callStack, std::string file1, Severity::SeverityType severity, const std::string &msg, std::string id, const CWE &cwe, Certainty::CertaintyLevel certainty) :
61+
ErrorMessage::ErrorMessage(std::list<FileLocation> callStack, std::string file1, Severity::SeverityType severity, const std::string &msg, std::string id, const CWE &cwe, Certainty certainty) :
6262
callStack(std::move(callStack)), // locations for this error message
6363
id(std::move(id)), // set the message id
6464
file0(std::move(file1)),
@@ -71,7 +71,7 @@ ErrorMessage::ErrorMessage(std::list<FileLocation> callStack, std::string file1,
7171
setmsg(msg);
7272
}
7373

74-
ErrorMessage::ErrorMessage(const std::list<const Token*>& callstack, const TokenList* list, Severity::SeverityType severity, std::string id, const std::string& msg, Certainty::CertaintyLevel certainty)
74+
ErrorMessage::ErrorMessage(const std::list<const Token*>& callstack, const TokenList* list, Severity::SeverityType severity, std::string id, const std::string& msg, Certainty certainty)
7575
: id(std::move(id)), severity(severity), cwe(0U), certainty(certainty), hash(0)
7676
{
7777
// Format callstack
@@ -90,7 +90,7 @@ ErrorMessage::ErrorMessage(const std::list<const Token*>& callstack, const Token
9090
}
9191

9292

93-
ErrorMessage::ErrorMessage(const std::list<const Token*>& callstack, const TokenList* list, Severity::SeverityType severity, std::string id, const std::string& msg, const CWE &cwe, Certainty::CertaintyLevel certainty)
93+
ErrorMessage::ErrorMessage(const std::list<const Token*>& callstack, const TokenList* list, Severity::SeverityType severity, std::string id, const std::string& msg, const CWE &cwe, Certainty certainty)
9494
: id(std::move(id)), severity(severity), cwe(cwe.id), certainty(certainty)
9595
{
9696
// Format callstack
@@ -110,7 +110,7 @@ ErrorMessage::ErrorMessage(const std::list<const Token*>& callstack, const Token
110110
hash = 0; // calculateWarningHash(list, hashWarning.str());
111111
}
112112

113-
ErrorMessage::ErrorMessage(const ErrorPath &errorPath, const TokenList *tokenList, Severity::SeverityType severity, const char id[], const std::string &msg, const CWE &cwe, Certainty::CertaintyLevel certainty)
113+
ErrorMessage::ErrorMessage(const ErrorPath &errorPath, const TokenList *tokenList, Severity::SeverityType severity, const char id[], const std::string &msg, const CWE &cwe, Certainty certainty)
114114
: id(id), severity(severity), cwe(cwe.id), certainty(certainty)
115115
{
116116
// Format callstack

lib/errorlogger.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -112,34 +112,34 @@ class CPPCHECKLIB ErrorMessage {
112112
std::string file1,
113113
Severity::SeverityType severity,
114114
const std::string &msg,
115-
std::string id, Certainty::CertaintyLevel certainty);
115+
std::string id, Certainty certainty);
116116
ErrorMessage(std::list<FileLocation> callStack,
117117
std::string file1,
118118
Severity::SeverityType severity,
119119
const std::string &msg,
120120
std::string id,
121121
const CWE &cwe,
122-
Certainty::CertaintyLevel certainty);
122+
Certainty certainty);
123123
ErrorMessage(const std::list<const Token*>& callstack,
124124
const TokenList* list,
125125
Severity::SeverityType severity,
126126
std::string id,
127127
const std::string& msg,
128-
Certainty::CertaintyLevel certainty);
128+
Certainty certainty);
129129
ErrorMessage(const std::list<const Token*>& callstack,
130130
const TokenList* list,
131131
Severity::SeverityType severity,
132132
std::string id,
133133
const std::string& msg,
134134
const CWE &cwe,
135-
Certainty::CertaintyLevel certainty);
135+
Certainty certainty);
136136
ErrorMessage(const ErrorPath &errorPath,
137137
const TokenList *tokenList,
138138
Severity::SeverityType severity,
139139
const char id[],
140140
const std::string &msg,
141141
const CWE &cwe,
142-
Certainty::CertaintyLevel certainty);
142+
Certainty certainty);
143143
ErrorMessage();
144144
explicit ErrorMessage(const tinyxml2::XMLElement * const errmsg);
145145

@@ -175,7 +175,7 @@ class CPPCHECKLIB ErrorMessage {
175175

176176
Severity::SeverityType severity;
177177
CWE cwe;
178-
Certainty::CertaintyLevel certainty;
178+
Certainty certainty;
179179

180180
/** Warning hash */
181181
std::size_t hash;

lib/errortypes.h

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -47,18 +47,12 @@ class TerminateException : public std::runtime_error {
4747
TerminateException() : std::runtime_error("terminate") {}
4848
};
4949

50-
class CPPCHECKLIB Certainty {
51-
public:
52-
enum CertaintyLevel {
53-
normal, inconclusive, safe, experimental
54-
};
50+
enum class Certainty {
51+
normal, inconclusive, safe, experimental
5552
};
5653

57-
class CPPCHECKLIB Checks {
58-
public:
59-
enum CheckList {
60-
unusedFunction, missingInclude, internalCheck
61-
};
54+
enum class Checks {
55+
unusedFunction, missingInclude, internalCheck
6256
};
6357

6458
/** @brief enum class for severity. Used when reporting errors. */

lib/settings.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -328,8 +328,8 @@ class CPPCHECKLIB Settings : public cppcheck::Platform {
328328
SafeChecks safeChecks;
329329

330330
SimpleEnableGroup<Severity::SeverityType> severity;
331-
SimpleEnableGroup<Certainty::CertaintyLevel> certainty;
332-
SimpleEnableGroup<Checks::CheckList> checks;
331+
SimpleEnableGroup<Certainty> certainty;
332+
SimpleEnableGroup<Checks> checks;
333333

334334
/** @brief show timing information (--showtime=file|summary|top5) */
335335
SHOWTIME_MODES showtime;

lib/suppressions.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ class CPPCHECKLIB Suppressions {
4747
return mFileName;
4848
}
4949
int lineNumber;
50-
Certainty::CertaintyLevel certainty;
50+
Certainty certainty;
5151
std::string symbolNames;
5252
private:
5353
std::string mFileName;

test/testerrorlogger.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,7 @@ class TestErrorLogger : public TestFixture {
254254
ASSERT_EQUALS("errorId", msg.id);
255255
ASSERT_EQUALS(Severity::error, msg.severity);
256256
ASSERT_EQUALS(123u, msg.cwe.id);
257-
ASSERT_EQUALS(Certainty::inconclusive, msg.certainty);
257+
ASSERT_EQUALS(static_cast<int>(Certainty::inconclusive), static_cast<int>(msg.certainty));
258258
ASSERT_EQUALS("Programming error.", msg.shortMessage());
259259
ASSERT_EQUALS("Verbose error", msg.verboseMessage());
260260
ASSERT_EQUALS(456u, msg.hash);
@@ -303,7 +303,7 @@ class TestErrorLogger : public TestFixture {
303303
ASSERT_EQUALS("errorId", msg2.id);
304304
ASSERT_EQUALS(Severity::error, msg2.severity);
305305
ASSERT_EQUALS("test.cpp", msg2.file0);
306-
ASSERT_EQUALS(Certainty::inconclusive, msg2.certainty);
306+
ASSERT_EQUALS(static_cast<int>(Certainty::inconclusive), static_cast<int>(msg2.certainty));
307307
ASSERT_EQUALS("Programming error", msg2.shortMessage());
308308
ASSERT_EQUALS("Programming error", msg2.verboseMessage());
309309
}

0 commit comments

Comments
 (0)