Skip to content

Commit 491f487

Browse files
authored
fixed/aligned some compiler warnings (cppcheck-opensource#3065)
1 parent 95d1b41 commit 491f487

6 files changed

Lines changed: 19 additions & 4 deletions

File tree

cmake/compileroptions.cmake

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ elseif (CMAKE_CXX_COMPILER_ID MATCHES "Clang")
5151
add_compile_options_safe(-Wdocumentation)
5252
add_compile_options_safe(-Wdocumentation-pedantic)
5353
add_compile_options_safe(-Wno-documentation-unknown-command)
54+
add_compile_options_safe(-Wimplicit-fallthrough)
5455

5556
if(ENABLE_COVERAGE OR ENABLE_COVERAGE_XML)
5657
message(FATAL_ERROR "Do not use clang for generate code coverage. Use gcc.")

gui/projectfile.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,7 @@ void ProjectFile::readBuildDir(QXmlStreamReader &reader)
248248
switch (type) {
249249
case QXmlStreamReader::Characters:
250250
mBuildDir = reader.text().toString();
251+
FALLTHROUGH;
251252
case QXmlStreamReader::EndElement:
252253
return;
253254
// Not handled
@@ -273,6 +274,7 @@ void ProjectFile::readImportProject(QXmlStreamReader &reader)
273274
switch (type) {
274275
case QXmlStreamReader::Characters:
275276
mImportProject = reader.text().toString();
277+
FALLTHROUGH;
276278
case QXmlStreamReader::EndElement:
277279
return;
278280
// Not handled
@@ -298,6 +300,7 @@ bool ProjectFile::readBool(QXmlStreamReader &reader)
298300
switch (type) {
299301
case QXmlStreamReader::Characters:
300302
ret = (reader.text().toString() == "true");
303+
FALLTHROUGH;
301304
case QXmlStreamReader::EndElement:
302305
return ret;
303306
// Not handled
@@ -323,6 +326,7 @@ int ProjectFile::readInt(QXmlStreamReader &reader, int defaultValue)
323326
switch (type) {
324327
case QXmlStreamReader::Characters:
325328
ret = reader.text().toString().toInt();
329+
FALLTHROUGH;
326330
case QXmlStreamReader::EndElement:
327331
return ret;
328332
// Not handled
@@ -617,6 +621,7 @@ void ProjectFile::readPlatform(QXmlStreamReader &reader)
617621
switch (type) {
618622
case QXmlStreamReader::Characters:
619623
mPlatform = reader.text().toString();
624+
FALLTHROUGH;
620625
case QXmlStreamReader::EndElement:
621626
return;
622627
// Not handled

lib/analyzer.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ struct Analyzer {
121121
/// If the analysis is unsure whether to update a scope, this will return true if the analysis should bifurcate the scope
122122
virtual bool updateScope(const Token* endBlock, bool modified) const = 0;
123123
/// Called when a scope will be forked
124-
virtual void forkScope(const Token* endBlock) {}
124+
virtual void forkScope(const Token* /*endBlock*/) {}
125125
/// If the value is conditional
126126
virtual bool isConditional() const = 0;
127127
/// The condition that will be assumed during analysis

lib/checkio.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -929,7 +929,7 @@ void CheckIO::checkFormatString(const Token * const tok,
929929
case 'l':
930930
if (i+1 != formatString.end() && *(i+1) == *i)
931931
specifier += *i++;
932-
// fallthrough
932+
FALLTHROUGH;
933933
case 'j':
934934
case 'q':
935935
case 't':
@@ -1255,7 +1255,7 @@ void CheckIO::checkFormatString(const Token * const tok,
12551255
specifier += *i++;
12561256
specifier += *i++;
12571257
}
1258-
// fallthrough
1258+
FALLTHROUGH;
12591259
case 'j': // intmax_t or uintmax_t
12601260
case 'z': // size_t
12611261
case 't': // ptrdiff_t

lib/checkstl.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1105,7 +1105,7 @@ void CheckStl::invalidContainerLoopError(const Token *tok, const Token * loopTok
11051105
reportError(errorPath, Severity::error, "invalidContainerLoop", msg, CWE664, false);
11061106
}
11071107

1108-
void CheckStl::invalidContainerError(const Token *tok, const Token * contTok, const ValueFlow::Value *val, ErrorPath errorPath)
1108+
void CheckStl::invalidContainerError(const Token *tok, const Token * /*contTok*/, const ValueFlow::Value *val, ErrorPath errorPath)
11091109
{
11101110
const bool inconclusive = val ? val->isInconclusive() : false;
11111111
if (val)

lib/config.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,15 @@
4646
# define NORETURN
4747
#endif
4848

49+
// fallthrough
50+
#if defined(__clang__)
51+
# define FALLTHROUGH [[clang::fallthrough]]
52+
#elif (defined(__GNUC__) && (__GNUC__ >= 7))
53+
# define FALLTHROUGH __attribute__((fallthrough))
54+
#else
55+
# define FALLTHROUGH
56+
#endif
57+
4958
#define REQUIRES(msg, ...) class=typename std::enable_if<__VA_ARGS__::value>::type
5059

5160
#include <string>

0 commit comments

Comments
 (0)