avoid some Clang compiler warnings (#3896)

This commit is contained in:
Oliver Stöneberg 2022-03-13 20:07:58 +01:00 committed by GitHub
parent a6c1653ed2
commit 0d336b868c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
45 changed files with 100 additions and 59 deletions

View File

@ -10,6 +10,11 @@ if(USE_BUNDLED_TINYXML2)
endif()
target_include_directories(cli_objs PRIVATE ${PROJECT_SOURCE_DIR}/externals/simplecpp/)
if (CMAKE_CXX_COMPILER_ID MATCHES "Clang" AND CMAKE_CXX_COMPILER_VERSION VERSION_LESS 14)
# false positive warning in up to Clang 13 - caused by FD_ZERO macro
set_source_files_properties(threadexecutor.cpp PROPERTIES COMPILE_FLAGS -Wno-reserved-identifier)
endif()
list(APPEND cppcheck_SOURCES ${hdrs} ${mainfile} $<TARGET_OBJECTS:cli_objs> $<TARGET_OBJECTS:lib_objs> $<TARGET_OBJECTS:simplecpp_objs>)
if(USE_BUNDLED_TINYXML2)
list(APPEND cppcheck_SOURCES $<TARGET_OBJECTS:tinyxml2_objs>)

View File

@ -66,7 +66,7 @@ elseif (CMAKE_CXX_COMPILER_ID MATCHES "Clang")
add_compile_options_safe(-Wno-shadow-field-in-constructor)
add_compile_options_safe(-Wno-covered-switch-default)
add_compile_options_safe(-Wno-shorten-64-to-32)
add_compile_options_safe(-Wno-zero-as-null-pointer-constant)
add_compile_options_safe(-Wno-zero-as-null-pointer-constant) # TODO: enable when warnings are fixed in in simplecpp and tinyxml2
add_compile_options_safe(-Wno-format-nonliteral)
add_compile_options_safe(-Wno-implicit-int-conversion)
add_compile_options_safe(-Wno-double-promotion)
@ -76,12 +76,13 @@ elseif (CMAKE_CXX_COMPILER_ID MATCHES "Clang")
add_compile_options_safe(-Wno-implicit-float-conversion)
add_compile_options_safe(-Wno-switch-enum)
add_compile_options_safe(-Wno-float-conversion)
add_compile_options_safe(-Wno-redundant-parens) # caused by Qt moc code
add_compile_options_safe(-Wno-enum-enum-conversion)
add_compile_options_safe(-Wno-date-time)
add_compile_options_safe(-Wno-suggest-override)
add_compile_options_safe(-Wno-suggest-destructor-override)
add_compile_options_safe(-Wno-conditional-uninitialized)
add_compile_options_safe(-Wno-suggest-override) # TODO: enable when warnings are fixed in in tinyxml2
add_compile_options_safe(-Wno-suggest-destructor-override) # TODO: enable when warnings are fixed in in tinyxml2
add_compile_options_safe(-Wno-extra-semi-stmt) # TODO: enable when warnings are fixed in in tinyxml2
add_compile_options(-Wno-disabled-macro-expansion)
# warnings we are not interested in
add_compile_options(-Wno-four-char-constants)
@ -89,8 +90,6 @@ elseif (CMAKE_CXX_COMPILER_ID MATCHES "Clang")
add_compile_options(-Wno-weak-vtables)
add_compile_options(-Wno-padded)
add_compile_options(-Wno-c++98-compat-pedantic)
add_compile_options(-Wno-disabled-macro-expansion)
add_compile_options(-Wno-reserved-id-macro)
add_compile_options_safe(-Wno-return-std-move-in-c++11)
if(ENABLE_COVERAGE OR ENABLE_COVERAGE_XML)

View File

@ -2,3 +2,6 @@ file(GLOB hdrs "*.h")
file(GLOB srcs "*.cpp")
add_library(simplecpp_objs OBJECT ${srcs} ${hdrs})
if (CMAKE_CXX_COMPILER_ID MATCHES "Clang")
target_compile_options_safe(simplecpp_objs -Wno-zero-as-null-pointer-constant)
endif()

View File

@ -10,5 +10,8 @@ endif()
if (CMAKE_CXX_COMPILER_ID MATCHES "Clang")
target_compile_options_safe(tinyxml2_objs -Wno-extra-semi-stmt)
target_compile_options_safe(tinyxml2_objs -Wno-implicit-fallthrough)
target_compile_options_safe(tinyxml2_objs -Wno-suggest-override)
target_compile_options_safe(tinyxml2_objs -Wno-suggest-destructor-override)
target_compile_options_safe(tinyxml2_objs -Wno-zero-as-null-pointer-constant)
endif()

View File

@ -44,10 +44,10 @@ if (BUILD_GUI)
target_link_libraries(cppcheck-gui ${QT_CHARTS_LIB})
endif()
if (CMAKE_CXX_COMPILER_ID MATCHES "Clang")
if (NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS "8.0.0")
# Q_UNUSED() in generated code
target_compile_options(cppcheck-gui PRIVATE -Wno-extra-semi-stmt)
endif()
# Q_UNUSED() in generated code
target_compile_options_safe(cppcheck-gui -Wno-extra-semi-stmt)
# caused by Qt generated moc code
target_compile_options_safe(cppcheck-gui -Wno-redundant-parens)
endif()
install(TARGETS cppcheck-gui RUNTIME DESTINATION ${CMAKE_INSTALL_FULL_BINDIR} COMPONENT applications)

View File

@ -49,7 +49,7 @@ public:
ApplicationDialog(const QString &title,
Application &app,
QWidget *parent = nullptr);
virtual ~ApplicationDialog();
~ApplicationDialog() override;
protected slots:

View File

@ -35,7 +35,7 @@ class ApplicationList : public QObject {
public:
explicit ApplicationList(QObject *parent = nullptr);
virtual ~ApplicationList();
~ApplicationList() override;
/**
* @brief Load all applications

View File

@ -39,7 +39,7 @@ class CheckThread : public QThread {
Q_OBJECT
public:
explicit CheckThread(ThreadResult &result);
virtual ~CheckThread();
~CheckThread() override;
/**
* @brief Set settings for cppcheck

View File

@ -80,7 +80,7 @@ public:
explicit CodeEditor(QWidget *parent);
CodeEditor(const CodeEditor &) = delete;
CodeEditor &operator=(const CodeEditor &) = delete;
~CodeEditor();
~CodeEditor() override;
void lineNumberAreaPaintEvent(QPaintEvent *event);
int lineNumberAreaWidth();

View File

@ -31,7 +31,7 @@ class SelectColorButton : public QPushButton {
Q_OBJECT
public:
explicit SelectColorButton(QWidget* parent);
virtual ~SelectColorButton() {}
~SelectColorButton() override {}
void setColor(const QColor& color);
const QColor& getColor();
@ -52,7 +52,7 @@ class SelectFontWeightCombo : public QComboBox {
Q_OBJECT
public:
explicit SelectFontWeightCombo(QWidget* parent);
virtual ~SelectFontWeightCombo() {}
~SelectFontWeightCombo() override {}
void setWeight(const QFont::Weight& weight);
const QFont::Weight& getWeight();

View File

@ -33,7 +33,7 @@ class StyleEditDialog : public QDialog {
public:
explicit StyleEditDialog(const CodeEditorStyle& newStyle,
QWidget *parent = nullptr);
virtual ~StyleEditDialog() {}
~StyleEditDialog() override {}
CodeEditorStyle getStyle();

View File

@ -37,7 +37,7 @@
class CsvReport : public Report {
public:
explicit CsvReport(const QString &filename);
virtual ~CsvReport();
~CsvReport() override;
/**
* @brief Create the report (file).

View File

@ -30,7 +30,7 @@ class FunctionContractDialog : public QDialog {
public:
explicit FunctionContractDialog(QWidget *parent, const QString &name, const QString &expects);
~FunctionContractDialog();
~FunctionContractDialog() override;
QString getExpects() const;
private:
Ui::FunctionContractDialog *mUi;

View File

@ -30,9 +30,9 @@ class QHelpEngine;
class HelpBrowser : public QTextBrowser {
public:
HelpBrowser(QWidget* parent = 0) : QTextBrowser(parent), mHelpEngine(nullptr) {}
HelpBrowser(QWidget* parent = nullptr) : QTextBrowser(parent), mHelpEngine(nullptr) {}
void setHelpEngine(QHelpEngine *helpEngine);
QVariant loadResource(int type, const QUrl& name);
QVariant loadResource(int type, const QUrl& name) override;
private:
QHelpEngine* mHelpEngine;
};
@ -42,7 +42,7 @@ class HelpDialog : public QDialog {
public:
explicit HelpDialog(QWidget *parent = nullptr);
~HelpDialog();
~HelpDialog() override;
private:
Ui::HelpDialog *mUi;

View File

@ -35,7 +35,7 @@ class LibraryAddFunctionDialog : public QDialog {
public:
explicit LibraryAddFunctionDialog(QWidget *parent = nullptr);
LibraryAddFunctionDialog(const LibraryAddFunctionDialog &) = delete;
~LibraryAddFunctionDialog();
~LibraryAddFunctionDialog() override;
LibraryAddFunctionDialog &operator=(const LibraryAddFunctionDialog &) = delete;
QString functionName() const;

View File

@ -35,7 +35,7 @@ class LibraryDialog : public QDialog {
public:
explicit LibraryDialog(QWidget *parent = nullptr);
LibraryDialog(const LibraryDialog &) = delete;
~LibraryDialog();
~LibraryDialog() override;
LibraryDialog &operator=(const LibraryDialog &) = delete;
private slots:

View File

@ -33,7 +33,7 @@ class LibraryEditArgDialog : public QDialog {
public:
LibraryEditArgDialog(QWidget *parent, const CppcheckLibraryData::Function::Arg &arg);
LibraryEditArgDialog(const LibraryEditArgDialog &) = delete;
~LibraryEditArgDialog();
~LibraryEditArgDialog() override;
LibraryEditArgDialog &operator=(const LibraryEditArgDialog &) = delete;
CppcheckLibraryData::Function::Arg getArg() const;

View File

@ -55,7 +55,7 @@ public:
MainWindow(TranslationHandler* th, QSettings* settings);
MainWindow(const MainWindow &) = delete;
virtual ~MainWindow();
~MainWindow() override;
MainWindow &operator=(const MainWindow &) = delete;
/**

View File

@ -33,7 +33,7 @@ class NewSuppressionDialog : public QDialog {
public:
explicit NewSuppressionDialog(QWidget *parent = nullptr);
NewSuppressionDialog(const NewSuppressionDialog &) = delete;
~NewSuppressionDialog();
~NewSuppressionDialog() override;
NewSuppressionDialog &operator=(const NewSuppressionDialog &) = delete;
/**

View File

@ -32,7 +32,7 @@
class PrintableReport : public Report {
public:
PrintableReport();
virtual ~PrintableReport();
~PrintableReport() override;
/**
* @brief Create the report (file).

View File

@ -46,7 +46,7 @@ class ProjectFile : public QObject {
public:
explicit ProjectFile(QObject *parent = nullptr);
explicit ProjectFile(const QString &filename, QObject *parent = nullptr);
~ProjectFile() {
~ProjectFile() override {
if (this == mActiveProject) mActiveProject = nullptr;
}

View File

@ -42,7 +42,7 @@ class ProjectFileDialog : public QDialog {
Q_OBJECT
public:
explicit ProjectFileDialog(ProjectFile *projectFile, QWidget *parent = nullptr);
virtual ~ProjectFileDialog();
~ProjectFileDialog() override;
private:
void loadFromProjectFile(const ProjectFile *projectFile);

View File

@ -40,7 +40,7 @@ public:
};
explicit Report(const QString &filename);
virtual ~Report();
~Report() override;
/**
* @brief Create the report (file).

View File

@ -49,7 +49,7 @@ class ResultsTree : public QTreeView {
Q_OBJECT
public:
explicit ResultsTree(QWidget * parent = nullptr);
virtual ~ResultsTree();
~ResultsTree() override;
void initialize(QSettings *settings, ApplicationList *list, ThreadHandler *checkThreadHandler);
/**

View File

@ -46,7 +46,7 @@ public:
explicit ResultsView(QWidget * parent = nullptr);
void initialize(QSettings *settings, ApplicationList *list, ThreadHandler *checkThreadHandler);
ResultsView(const ResultsView &) = delete;
virtual ~ResultsView();
~ResultsView() override;
ResultsView &operator=(const ResultsView &) = delete;
void setAddedFunctionContracts(const QStringList &addedContracts);
@ -372,7 +372,7 @@ protected:
CheckStatistics *mStatistics;
bool eventFilter(QObject *target, QEvent *event);
bool eventFilter(QObject *target, QEvent *event) override;
private slots:
/**
* @brief Custom context menu for Analysis Log

View File

@ -44,7 +44,7 @@ public:
TranslationHandler *translator,
QWidget *parent = nullptr);
SettingsDialog(const SettingsDialog &) = delete;
virtual ~SettingsDialog();
~SettingsDialog() override;
SettingsDialog &operator=(const SettingsDialog &) = delete;
/**

View File

@ -21,4 +21,13 @@ if (USE_Z3)
endif()
if(tinyxml2_FOUND AND NOT USE_BUNDLED_TINYXML2)
target_link_libraries(benchmark-simple ${tinyxml2_LIBRARY})
endif()
if (CMAKE_CXX_COMPILER_ID MATCHES "Clang")
if (CMAKE_CXX_COMPILER_VERSION VERSION_LESS 14)
# false positive in up to CLang 13 - caused by QBENCHMARK macro
set_source_files_properties(benchmarksimple.cpp PROPERTIES COMPILE_FLAGS -Wno-reserved-identifier)
endif()
# caused by Q_UNUSED macro
set_source_files_properties(moc_benchmarksimple.cpp PROPERTIES COMPILE_FLAGS -Wno-extra-semi-stmt)
endif()

View File

@ -7,4 +7,9 @@ add_executable(test-cppchecklibrarydata
${CMAKE_SOURCE_DIR}/gui/cppchecklibrarydata.cpp
)
target_include_directories(test-cppchecklibrarydata PRIVATE ${CMAKE_SOURCE_DIR}/gui)
target_link_libraries(test-cppchecklibrarydata ${QT_CORE_LIB} ${QT_TEST_LIB})
target_link_libraries(test-cppchecklibrarydata ${QT_CORE_LIB} ${QT_TEST_LIB})
if (CMAKE_CXX_COMPILER_ID MATCHES "Clang")
# Q_UNUSED() in generated code
target_compile_options_safe(test-cppchecklibrarydata -Wno-extra-semi-stmt)
endif()

View File

@ -12,4 +12,9 @@ add_executable(test-filelist
)
target_include_directories(test-filelist PRIVATE ${CMAKE_SOURCE_DIR}/gui ${CMAKE_SOURCE_DIR}/lib ${CMAKE_SOURCE_DIR}/externals/simplecpp)
target_compile_definitions(test-filelist PRIVATE SRCDIR="${CMAKE_CURRENT_SOURCE_DIR}")
target_link_libraries(test-filelist ${QT_CORE_LIB} ${QT_TEST_LIB})
target_link_libraries(test-filelist ${QT_CORE_LIB} ${QT_TEST_LIB})
if (CMAKE_CXX_COMPILER_ID MATCHES "Clang")
# Q_UNUSED() in generated code
target_compile_options_safe(test-filelist -Wno-extra-semi-stmt)
endif()

View File

@ -8,4 +8,9 @@ add_executable(test-projectfile
)
target_include_directories(test-projectfile PRIVATE ${CMAKE_SOURCE_DIR}/gui ${CMAKE_SOURCE_DIR}/lib)
target_compile_definitions(test-projectfile PRIVATE SRCDIR="${CMAKE_CURRENT_SOURCE_DIR}")
target_link_libraries(test-projectfile ${QT_CORE_LIB} ${QT_TEST_LIB})
target_link_libraries(test-projectfile ${QT_CORE_LIB} ${QT_TEST_LIB})
if (CMAKE_CXX_COMPILER_ID MATCHES "Clang")
# Q_UNUSED() in generated code
target_compile_options_safe(test-projectfile -Wno-extra-semi-stmt)
endif()

View File

@ -8,4 +8,9 @@ add_executable(test-translationhandler
${CMAKE_SOURCE_DIR}/gui/translationhandler.cpp
)
target_include_directories(test-translationhandler PRIVATE ${CMAKE_SOURCE_DIR}/gui)
target_link_libraries(test-translationhandler ${QT_CORE_LIB} ${QT_WIDGETS_LIB} ${QT_TEST_LIB})
target_link_libraries(test-translationhandler ${QT_CORE_LIB} ${QT_WIDGETS_LIB} ${QT_TEST_LIB})
if (CMAKE_CXX_COMPILER_ID MATCHES "Clang")
# Q_UNUSED() in generated code
target_compile_options_safe(test-projectfile -Wno-extra-semi-stmt)
endif()

View File

@ -48,7 +48,7 @@ class ThreadHandler : public QObject {
Q_OBJECT
public:
explicit ThreadHandler(QObject *parent = nullptr);
virtual ~ThreadHandler();
~ThreadHandler() override;
/**
* @brief Set the number of threads to use

View File

@ -41,7 +41,7 @@ class ThreadResult : public QObject, public ErrorLogger {
Q_OBJECT
public:
ThreadResult();
virtual ~ThreadResult();
~ThreadResult() override;
/**
* @brief Get next unprocessed file

View File

@ -62,7 +62,7 @@ class TranslationHandler : QObject {
Q_OBJECT
public:
explicit TranslationHandler(QObject *parent = nullptr);
virtual ~TranslationHandler();
~TranslationHandler() override;
/**
* @brief Get a list of available translations.

View File

@ -37,7 +37,7 @@ class TxtReport : public Report {
public:
explicit TxtReport(const QString &filename);
virtual ~TxtReport();
~TxtReport() override;
/**
* @brief Create the report (file).

View File

@ -30,7 +30,7 @@ class VariableContractsDialog : public QDialog {
public:
explicit VariableContractsDialog(QWidget *parent, QString var);
~VariableContractsDialog();
~VariableContractsDialog() override;
QString getVarname() const;
QString getMin() const;

View File

@ -38,7 +38,7 @@ class QXmlStreamWriter;
class XmlReportV2 : public XmlReport {
public:
explicit XmlReportV2(const QString &filename);
virtual ~XmlReportV2();
~XmlReportV2() override;
/**
* @brief Create the report (file).

View File

@ -88,6 +88,7 @@ static bool isVariableCopyNeeded(const Variable &var, Function::Type type)
switch (type) {
case Function::eOperatorEqual:
isOpEqual = true;
break;
case Function::eCopyConstructor:
case Function::eMoveConstructor:
break;

View File

@ -180,11 +180,11 @@ void ProgramMemory::insert(const ProgramMemory &pm)
mValues.insert(p);
}
bool evaluateCondition(const std::string& op,
MathLib::bigint r,
const Token* condition,
ProgramMemory& pm,
const Settings* settings)
static bool evaluateCondition(const std::string& op,
MathLib::bigint r,
const Token* condition,
ProgramMemory& pm,
const Settings* settings)
{
if (!condition)
return false;

View File

@ -147,14 +147,14 @@ void execute(const Token* expr,
/**
* Is condition always false when variable has given value?
* \param condition top ast token in condition
* \param programMemory program memory
* \param pm program memory
*/
bool conditionIsFalse(const Token* condition, ProgramMemory pm, const Settings* settings = nullptr);
/**
* Is condition always true when variable has given value?
* \param condition top ast token in condition
* \param programMemory program memory
* \param pm program memory
*/
bool conditionIsTrue(const Token* condition, ProgramMemory pm, const Settings* settings = nullptr);

View File

@ -2065,6 +2065,7 @@ static void mergeAdjacent(std::list<ValueFlow::Value>& values)
continue;
}
std::sort(adjValues.begin(), adjValues.end(), [&values](ValueIterator xx, ValueIterator yy) {
(void)values;
assert(xx != values.end() && yy != values.end());
return xx->compareValue(*yy, ValueFlow::less{});
});

View File

@ -3741,7 +3741,7 @@ struct LifetimeStore {
// Don't add the value a second time
if (std::find(tok->values().begin(), tok->values().end(), value) != tok->values().end())
continue;
;
setTokenValue(tok, value, tokenlist->getSettings());
update = true;
}

View File

@ -14,7 +14,7 @@ add_executable(dmake EXCLUDE_FROM_ALL
${CMAKE_SOURCE_DIR}/cli/filelister.cpp
${srcs_tools}
${CMAKE_SOURCE_DIR}/lib/utils.cpp
${CMAKE_SOURCE_DIR}/externals/simplecpp/simplecpp.cpp
$<TARGET_OBJECTS:simplecpp_objs>
)
target_include_directories(dmake PRIVATE ${CMAKE_SOURCE_DIR}/cli ${CMAKE_SOURCE_DIR}/lib ${CMAKE_SOURCE_DIR}/externals/simplecpp)
if (WIN32 AND NOT BORLAND)

View File

@ -24,9 +24,9 @@ if (BUILD_GUI AND BUILD_TESTS)
target_include_directories(triage PRIVATE ${PROJECT_SOURCE_DIR}/lib/ ${PROJECT_SOURCE_DIR}/gui/)
target_link_libraries(triage ${QT_CORE_LIB} ${QT_GUI_LIB} ${QT_WIDGETS_LIB})
if (CMAKE_CXX_COMPILER_ID MATCHES "Clang")
if (NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS "8.0.0")
# Q_UNUSED() in generated code
target_compile_options(triage PRIVATE -Wno-extra-semi-stmt)
endif()
# Q_UNUSED() in generated code
target_compile_options_safe(triage -Wno-extra-semi-stmt)
# caused by Qt generated moc code
target_compile_options_safe(triage -Wno-redundant-parens)
endif()
endif()

View File

@ -36,7 +36,7 @@ public:
explicit MainWindow(QWidget *parent = nullptr);
MainWindow(const MainWindow &) = delete;
MainWindow &operator=(const MainWindow &) = delete;
~MainWindow();
~MainWindow() override;
public slots:
void loadFile();