From 491f4874c588285b7f19c0b29b242c034ff92c62 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Oliver=20St=C3=B6neberg?= Date: Thu, 21 Jan 2021 18:13:32 +0100 Subject: [PATCH] fixed/aligned some compiler warnings (#3065) --- cmake/compileroptions.cmake | 1 + gui/projectfile.cpp | 5 +++++ lib/analyzer.h | 2 +- lib/checkio.cpp | 4 ++-- lib/checkstl.cpp | 2 +- lib/config.h | 9 +++++++++ 6 files changed, 19 insertions(+), 4 deletions(-) diff --git a/cmake/compileroptions.cmake b/cmake/compileroptions.cmake index 8f7b766e2..55656446b 100644 --- a/cmake/compileroptions.cmake +++ b/cmake/compileroptions.cmake @@ -51,6 +51,7 @@ elseif (CMAKE_CXX_COMPILER_ID MATCHES "Clang") add_compile_options_safe(-Wdocumentation) add_compile_options_safe(-Wdocumentation-pedantic) add_compile_options_safe(-Wno-documentation-unknown-command) + add_compile_options_safe(-Wimplicit-fallthrough) if(ENABLE_COVERAGE OR ENABLE_COVERAGE_XML) message(FATAL_ERROR "Do not use clang for generate code coverage. Use gcc.") diff --git a/gui/projectfile.cpp b/gui/projectfile.cpp index e3f986f7b..f6accf5ad 100644 --- a/gui/projectfile.cpp +++ b/gui/projectfile.cpp @@ -248,6 +248,7 @@ void ProjectFile::readBuildDir(QXmlStreamReader &reader) switch (type) { case QXmlStreamReader::Characters: mBuildDir = reader.text().toString(); + FALLTHROUGH; case QXmlStreamReader::EndElement: return; // Not handled @@ -273,6 +274,7 @@ void ProjectFile::readImportProject(QXmlStreamReader &reader) switch (type) { case QXmlStreamReader::Characters: mImportProject = reader.text().toString(); + FALLTHROUGH; case QXmlStreamReader::EndElement: return; // Not handled @@ -298,6 +300,7 @@ bool ProjectFile::readBool(QXmlStreamReader &reader) switch (type) { case QXmlStreamReader::Characters: ret = (reader.text().toString() == "true"); + FALLTHROUGH; case QXmlStreamReader::EndElement: return ret; // Not handled @@ -323,6 +326,7 @@ int ProjectFile::readInt(QXmlStreamReader &reader, int defaultValue) switch (type) { case QXmlStreamReader::Characters: ret = reader.text().toString().toInt(); + FALLTHROUGH; case QXmlStreamReader::EndElement: return ret; // Not handled @@ -617,6 +621,7 @@ void ProjectFile::readPlatform(QXmlStreamReader &reader) switch (type) { case QXmlStreamReader::Characters: mPlatform = reader.text().toString(); + FALLTHROUGH; case QXmlStreamReader::EndElement: return; // Not handled diff --git a/lib/analyzer.h b/lib/analyzer.h index b2a1dad4d..502407a53 100644 --- a/lib/analyzer.h +++ b/lib/analyzer.h @@ -121,7 +121,7 @@ struct Analyzer { /// If the analysis is unsure whether to update a scope, this will return true if the analysis should bifurcate the scope virtual bool updateScope(const Token* endBlock, bool modified) const = 0; /// Called when a scope will be forked - virtual void forkScope(const Token* endBlock) {} + virtual void forkScope(const Token* /*endBlock*/) {} /// If the value is conditional virtual bool isConditional() const = 0; /// The condition that will be assumed during analysis diff --git a/lib/checkio.cpp b/lib/checkio.cpp index 2390d53d4..2f59b5edd 100644 --- a/lib/checkio.cpp +++ b/lib/checkio.cpp @@ -929,7 +929,7 @@ void CheckIO::checkFormatString(const Token * const tok, case 'l': if (i+1 != formatString.end() && *(i+1) == *i) specifier += *i++; - // fallthrough + FALLTHROUGH; case 'j': case 'q': case 't': @@ -1255,7 +1255,7 @@ void CheckIO::checkFormatString(const Token * const tok, specifier += *i++; specifier += *i++; } - // fallthrough + FALLTHROUGH; case 'j': // intmax_t or uintmax_t case 'z': // size_t case 't': // ptrdiff_t diff --git a/lib/checkstl.cpp b/lib/checkstl.cpp index f4bc4f8f2..69b94e815 100644 --- a/lib/checkstl.cpp +++ b/lib/checkstl.cpp @@ -1105,7 +1105,7 @@ void CheckStl::invalidContainerLoopError(const Token *tok, const Token * loopTok reportError(errorPath, Severity::error, "invalidContainerLoop", msg, CWE664, false); } -void CheckStl::invalidContainerError(const Token *tok, const Token * contTok, const ValueFlow::Value *val, ErrorPath errorPath) +void CheckStl::invalidContainerError(const Token *tok, const Token * /*contTok*/, const ValueFlow::Value *val, ErrorPath errorPath) { const bool inconclusive = val ? val->isInconclusive() : false; if (val) diff --git a/lib/config.h b/lib/config.h index 4bbb80359..c6034d6e6 100644 --- a/lib/config.h +++ b/lib/config.h @@ -46,6 +46,15 @@ # define NORETURN #endif +// fallthrough +#if defined(__clang__) +# define FALLTHROUGH [[clang::fallthrough]] +#elif (defined(__GNUC__) && (__GNUC__ >= 7)) +# define FALLTHROUGH __attribute__((fallthrough)) +#else +# define FALLTHROUGH +#endif + #define REQUIRES(msg, ...) class=typename std::enable_if<__VA_ARGS__::value>::type #include