Skip to content

Commit

Permalink
added xml.h wrapper for TinyXML2 / cleaned up suppressions of Clang…
Browse files Browse the repository at this point in the history
… compiler warnings (#5700)
  • Loading branch information
firewave committed Nov 26, 2023
1 parent 42a64d4 commit f246178
Show file tree
Hide file tree
Showing 25 changed files with 125 additions and 81 deletions.
32 changes: 16 additions & 16 deletions Makefile

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion cli/cmdlineparser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@

#ifdef HAVE_RULES
// xml is used for rules
#include <tinyxml2.h>
#include "xml.h"
#endif

static bool addFilesToList(const std::string& fileList, std::vector<std::string>& pathNames)
Expand Down
79 changes: 37 additions & 42 deletions cmake/compileroptions.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -80,53 +80,48 @@ elseif (CMAKE_CXX_COMPILER_ID MATCHES "Clang")
add_link_options(-lc++)
endif()

# TODO: fix and enable these warnings - or move to suppression list below
# TODO: fix and enable these warnings - or move to suppression list below
add_compile_options_safe(-Wno-documentation-unknown-command) # TODO: Clang currently does not support all commands
add_compile_options_safe(-Wno-inconsistent-missing-destructor-override) # caused by Qt moc code
add_compile_options_safe(-Wno-unused-exception-parameter)
add_compile_options_safe(-Wno-old-style-cast)
add_compile_options_safe(-Wno-sign-conversion)
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) # TODO: enable when warnings are fixed in in simplecpp and tinyxml2
add_compile_options_safe(-Wno-implicit-int-conversion)
add_compile_options_safe(-Wno-double-promotion)
add_compile_options_safe(-Wno-shadow-field)
add_compile_options_safe(-Wno-shadow-uncaptured-local)
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-enum-enum-conversion)
add_compile_options_safe(-Wno-date-time)
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)
add_compile_options_safe(-Wno-bitwise-instead-of-logical)

# these cannot be fixed properly without adopting later C++ standards
add_compile_options_safe(-Wno-unsafe-buffer-usage)
add_compile_options_safe(-Wno-global-constructors)
add_compile_options_safe(-Wno-exit-time-destructors)

# can only be partially addressed
add_compile_options(-Wno-padded)

# no need for C++98 compatibility
add_compile_options(-Wno-c++98-compat)
add_compile_options(-Wno-c++98-compat-pedantic)

# only need to be addressed to work around issues in older compilers
add_compile_options_safe(-Wno-return-std-move-in-c++11)
add_compile_options_safe(-Wno-unused-exception-parameter)
add_compile_options_safe(-Wno-old-style-cast)
add_compile_options_safe(-Wno-sign-conversion)
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-implicit-int-conversion)
add_compile_options_safe(-Wno-double-promotion)
add_compile_options_safe(-Wno-shadow-field)
add_compile_options_safe(-Wno-shadow-uncaptured-local)
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-enum-enum-conversion)
add_compile_options_safe(-Wno-date-time)
add_compile_options(-Wno-disabled-macro-expansion)
add_compile_options_safe(-Wno-bitwise-instead-of-logical)

# these cannot be fixed properly without adopting later C++ standards
add_compile_options_safe(-Wno-unsafe-buffer-usage)
add_compile_options_safe(-Wno-global-constructors)
add_compile_options_safe(-Wno-exit-time-destructors)

# can only be partially addressed
add_compile_options(-Wno-padded)

# no need for C++98 compatibility
add_compile_options(-Wno-c++98-compat)
add_compile_options(-Wno-c++98-compat-pedantic)

# only needs to be addressed to work around issues in older compilers
add_compile_options_safe(-Wno-return-std-move-in-c++11)

# warnings we are currently not interested in
add_compile_options(-Wno-four-char-constants)
add_compile_options(-Wno-weak-vtables)
add_compile_options(-Wno-four-char-constants)
add_compile_options(-Wno-weak-vtables)

if(ENABLE_COVERAGE OR ENABLE_COVERAGE_XML)
if(ENABLE_COVERAGE OR ENABLE_COVERAGE_XML)
message(FATAL_ERROR "Do not use clang to generate code coverage. Use GCC instead.")
endif()
endif()
endif()

if (MSVC)
Expand Down
3 changes: 3 additions & 0 deletions gui/test/xmlreportv2/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ if (BUILD_CORE_DLL)
target_compile_definitions(test-xmlreportv2 PRIVATE CPPCHECKLIB_IMPORT TINYXML2_IMPORT)
target_link_libraries(test-xmlreportv2 cppcheck-core)
endif()
if (CMAKE_CXX_COMPILER_ID MATCHES "Clang")
target_compile_options_safe(test-xmlreportv2 -Wno-extra-semi-stmt)
endif()

if (REGISTER_GUI_TESTS)
add_test(NAME test-xmlreportv2 COMMAND $<TARGET_FILE:test-xmlreportv2>)
Expand Down
3 changes: 2 additions & 1 deletion lib/analyzerinfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,12 @@
#include "path.h"
#include "utils.h"

#include <tinyxml2.h>
#include <cstring>
#include <map>
#include <sstream> // IWYU pragma: keep

#include "xml.h"

AnalyzerInformation::~AnalyzerInformation()
{
close();
Expand Down
3 changes: 2 additions & 1 deletion lib/checkbufferoverrun.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@
#include <iterator>
#include <numeric> // std::accumulate
#include <sstream>
#include <tinyxml2.h>

#include "xml.h"

//---------------------------------------------------------------------------

Expand Down
13 changes: 7 additions & 6 deletions lib/checkclass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
#include <utility>
#include <unordered_map>

#include <tinyxml2.h>
#include "xml.h"

namespace CTU {
class FileInfo;
Expand Down Expand Up @@ -2523,14 +2523,15 @@ bool CheckClass::checkConstFunc(const Scope *scope, const Function *func, Member
((lastVarTok->valueType()->container->getYield(end->str()) == Library::Container::Yield::START_ITERATOR) ||
(lastVarTok->valueType()->container->getYield(end->str()) == Library::Container::Yield::END_ITERATOR))
&& (tok1->previous()->isComparisonOp() ||
(tok1->previous()->isAssignmentOp() && tok1->tokAt(-2)->variable() && Token::Match(tok1->tokAt(-2)->variable()->typeEndToken(), "const_iterator|const_reverse_iterator")))))
;
(tok1->previous()->isAssignmentOp() && tok1->tokAt(-2)->variable() && Token::Match(tok1->tokAt(-2)->variable()->typeEndToken(), "const_iterator|const_reverse_iterator"))))) {
// empty body
}
else if (var->smartPointerType() && var->smartPointerType()->classScope && isConstMemberFunc(var->smartPointerType()->classScope, end)) {
;
// empty body
} else if (var->isSmartPointer() && Token::simpleMatch(tok1->next(), ".") && tok1->next()->originalName().empty() && mSettings->library.isFunctionConst(end)) {
;
// empty body
} else if (hasOverloadedMemberAccess(end, var->typeScope())) {
;
// empty body
} else if (!var->typeScope() || (end->function() != func && !isConstMemberFunc(var->typeScope(), end))) {
if (!mSettings->library.isFunctionConst(end))
return false;
Expand Down
2 changes: 1 addition & 1 deletion lib/checkmemoryleak.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -753,7 +753,7 @@ void CheckMemoryLeakStructMember::checkStructVariable(const Variable* const vari
deallocated = true;
break;
}
};
}

return deallocated;
};
Expand Down
2 changes: 1 addition & 1 deletion lib/checkunusedfunctions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
#include <utility>
#include <vector>

#include <tinyxml2.h>
#include "xml.h"

namespace CTU {
class FileInfo;
Expand Down
2 changes: 1 addition & 1 deletion lib/cppcheck.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@

#include <simplecpp.h>

#include <tinyxml2.h>
#include "xml.h"

#ifdef HAVE_RULES
#ifdef _WIN32
Expand Down
1 change: 1 addition & 0 deletions lib/cppcheck.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,7 @@
<ClInclude Include="valueptr.h" />
<ClInclude Include="version.h" />
<ClInclude Include="vfvalue.h" />
<ClInclude Include="xml.h" />
</ItemGroup>
<ItemGroup>
<ResourceCompile Include="version.rc" />
Expand Down
2 changes: 1 addition & 1 deletion lib/ctu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
#include <sstream>
#include <utility>

#include <tinyxml2.h>
#include "xml.h"
//---------------------------------------------------------------------------

static constexpr char ATTR_CALL_ID[] = "call-id";
Expand Down
2 changes: 1 addition & 1 deletion lib/errorlogger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
#include <unordered_map>
#include <utility>

#include <tinyxml2.h>
#include "xml.h"

const std::set<std::string> ErrorLogger::mCriticalErrorIds{
"cppcheckError",
Expand Down
2 changes: 1 addition & 1 deletion lib/importproject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
#include <unordered_set>
#include <utility>

#include <tinyxml2.h>
#include "xml.h"

#include "json.h"

Expand Down
4 changes: 4 additions & 0 deletions lib/json.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,17 @@
#ifndef jsonH
#define jsonH

#include "config.h"

SUPPRESS_WARNING_PUSH("-Wfloat-equal")
SUPPRESS_WARNING_CLANG_PUSH("-Wtautological-type-limit-compare")
SUPPRESS_WARNING_GCC_PUSH("-Wparentheses")
SUPPRESS_WARNING_CLANG_PUSH("-Wextra-semi-stmt")

#define PICOJSON_USE_INT64
#include <picojson.h>

SUPPRESS_WARNING_CLANG_POP
SUPPRESS_WARNING_GCC_POP
SUPPRESS_WARNING_CLANG_POP
SUPPRESS_WARNING_POP
Expand Down
3 changes: 2 additions & 1 deletion lib/lib.pri
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,8 @@ HEADERS += $${PWD}/addoninfo.h \
$${PWD}/valueflow.h \
$${PWD}/valueptr.h \
$${PWD}/version.h \
$${PWD}/vfvalue.h
$${PWD}/vfvalue.h \
$${PWD}/xml.h

SOURCES += $${PWD}/valueflow.cpp \
$${PWD}/tokenize.cpp \
Expand Down
2 changes: 1 addition & 1 deletion lib/library.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
#include <stdexcept>
#include <string>

#include <tinyxml2.h>
#include "xml.h"

static std::vector<std::string> getnames(const char *names)
{
Expand Down
2 changes: 1 addition & 1 deletion lib/platform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
#include <limits>
#include <vector>

#include <tinyxml2.h>
#include "xml.h"

Platform::Platform()
{
Expand Down
2 changes: 1 addition & 1 deletion lib/suppressions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
#include <sstream> // IWYU pragma: keep
#include <utility>

#include <tinyxml2.h>
#include "xml.h"

Suppressions::ErrorMessage Suppressions::ErrorMessage::fromErrorMessage(const ::ErrorMessage &msg, const std::set<std::string> &macroNames)
{
Expand Down
36 changes: 36 additions & 0 deletions lib/xml.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
* Cppcheck - A tool for static C/C++ code analysis
* Copyright (C) 2007-2023 Cppcheck team.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

#ifndef xmlH
#define xmlH

#include "config.h"

SUPPRESS_WARNING_CLANG_PUSH("-Wzero-as-null-pointer-constant")
SUPPRESS_WARNING_CLANG_PUSH("-Wextra-semi-stmt")
SUPPRESS_WARNING_CLANG_PUSH("-Wsuggest-override")
SUPPRESS_WARNING_CLANG_PUSH("-Wsuggest-destructor-override")

#include <tinyxml2.h>

SUPPRESS_WARNING_CLANG_POP
SUPPRESS_WARNING_CLANG_POP
SUPPRESS_WARNING_CLANG_POP
SUPPRESS_WARNING_CLANG_POP

#endif // xmlH
2 changes: 1 addition & 1 deletion test/fixture.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
#include <sstream>
#include <string>

#include <tinyxml2.h>
#include "xml.h"

std::ostringstream errout;
std::ostringstream output;
Expand Down
2 changes: 1 addition & 1 deletion test/testerrorlogger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
#include <list>
#include <string>

#include <tinyxml2.h>
#include "xml.h"

class TestErrorLogger : public TestFixture {
public:
Expand Down
2 changes: 1 addition & 1 deletion test/testlibrary.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
#include <unordered_map>
#include <vector>

#include <tinyxml2.h>
#include "xml.h"

#define ASSERT_EQ(expected, actual) ASSERT(expected == actual)

Expand Down
2 changes: 1 addition & 1 deletion test/testplatform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

#include <string>

#include <tinyxml2.h>
#include "xml.h"


class TestPlatform : public TestFixture {
Expand Down
1 change: 1 addition & 0 deletions tools/dmake.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,7 @@ int main(int argc, char **argv)
libfiles_h.emplace_back("tokenrange.h");
libfiles_h.emplace_back("valueptr.h");
libfiles_h.emplace_back("version.h");
libfiles_h.emplace_back("xml.h");
std::sort(libfiles_h.begin(), libfiles_h.end());

std::vector<std::string> clifiles_h;
Expand Down

0 comments on commit f246178

Please sign in to comment.