use -Weverything for clang in CMake / fixed some warnings (#3519)

This commit is contained in:
Oliver Stöneberg 2021-10-24 11:06:48 +02:00 committed by GitHub
parent 7004ceb691
commit cc1a18806c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 48 additions and 56 deletions

View File

@ -14,6 +14,10 @@ function(target_compile_options_safe TARGET FLAG)
endif()
endfunction()
if (CMAKE_CXX_COMPILER_ID MATCHES "Clang")
add_compile_options(-Weverything)
endif()
if (CMAKE_CXX_COMPILER_ID MATCHES "GNU" OR CMAKE_CXX_COMPILER_ID MATCHES "Clang")
if(CMAKE_BUILD_TYPE MATCHES "Release")
# "Release" uses -O3 by default
@ -33,7 +37,6 @@ if (CMAKE_CXX_COMPILER_ID MATCHES "GNU" OR CMAKE_CXX_COMPILER_ID MATCHES "Clang"
add_compile_options(-Wpacked) #
add_compile_options(-Wredundant-decls) # if anything is declared more than once in the same scope
add_compile_options(-Wundef)
add_compile_options(-Wno-shadow) # whenever a local variable or type declaration shadows another one
add_compile_options(-Wno-missing-field-initializers)
add_compile_options(-Wno-missing-braces)
add_compile_options(-Wno-sign-compare)
@ -48,18 +51,49 @@ if (CMAKE_CXX_COMPILER_ID MATCHES "GNU")
add_compile_options(-Woverloaded-virtual) # when a function declaration hides virtual functions from a base class
add_compile_options(-Wno-maybe-uninitialized) # there are some false positives
add_compile_options(-Wsuggest-attribute=noreturn)
add_compile_options(-Wno-shadow) # whenever a local variable or type declaration shadows another one
elseif (CMAKE_CXX_COMPILER_ID MATCHES "Clang")
add_compile_options(-Wno-four-char-constants)
add_compile_options(-Wno-missing-braces)
add_compile_options(-Wno-unused-function)
add_compile_options_safe(-Wextra-semi-stmt)
add_compile_options_safe(-Wcomma)
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)
add_compile_options_safe(-Wmissing-noreturn)
# TODO: fix and enable these warnings - or move to suppression list below
add_compile_options_safe(-Wno-deprecated-copy-dtor)
add_compile_options_safe(-Wno-non-virtual-dtor)
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-global-constructors)
add_compile_options_safe(-Wno-exit-time-destructors)
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)
add_compile_options_safe(-Wno-format-nonliteral)
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-unreachable-code)
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)
# warnings we are not interested in
add_compile_options(-Wno-four-char-constants)
add_compile_options(-Wno-c++98-compat)
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)
message(FATAL_ERROR "Do not use clang for generate code coverage. Use gcc.")

View File

@ -7,6 +7,7 @@ macro(use_cxx11)
endif ()
else ()
set (CMAKE_CXX_STANDARD 11)
set (CMAKE_CXX_STANDARD_REQUIRED ON)
if (POLICY CMP0025)
cmake_policy(SET CMP0025 NEW)
endif ()

View File

@ -51,7 +51,9 @@
#include <cstdio>
#ifdef HAVE_RULES
#ifdef _WIN32
#define PCRE_STATIC
#endif
#include <pcre.h>
#endif

View File

@ -61,4 +61,4 @@ Severity::SeverityType Severity::fromString(const std::string& severity)
if (severity == "debug")
return debug;
return none;
}
}

View File

@ -574,10 +574,6 @@ namespace {
mTrackExecution->addMissingContract(f);
}
const std::set<std::string> getMissingContracts() const {
return mTrackExecution->getMissingContracts();
}
ExprEngine::ValuePtr notValue(ExprEngine::ValuePtr v) {
auto b = std::dynamic_pointer_cast<ExprEngine::BinOpResult>(v);
if (b) {

View File

@ -1794,47 +1794,6 @@ namespace {
return false;
}
void printOut(const std::string & indent = " ") const {
std::cerr << indent << "type: " << (type == Global ? "Global" :
type == Namespace ? "Namespace" :
type == Record ? "Record" :
type == MemberFunction ? "MemberFunction" :
type == Other ? "Other" :
"Unknown") << std::endl;
std::cerr << indent << "fullName: " << fullName << std::endl;
std::cerr << indent << "name: " << name << std::endl;
std::cerr << indent << usingNamespaces.size() << " usingNamespaces:";
for (const auto & usingNamespace : usingNamespaces)
std::cerr << " " << usingNamespace;
std::cerr << std::endl;
std::cerr << indent << baseTypes.size() << " baseTypes:";
for (const auto & baseType : baseTypes)
std::cerr << " " << baseType;
std::cerr << std::endl;
std::cerr << indent << children.size() << " children:" << std::endl;
size_t i = 0;
for (const auto & child : children) {
std::cerr << indent << "child " << i++ << std::endl;
child.printOut(indent + " ");
}
}
const ScopeInfo3 * findScopeRecursive(const std::string & scope) const {
if (fullName.size() < scope.size() &&
fullName == scope.substr(0, fullName.size())) {
for (const auto & child : children) {
if (child.fullName == scope && &child != this)
return &child;
else {
const ScopeInfo3 * temp1 = child.findScopeRecursive(scope);
if (temp1)
return temp1;
}
}
}
return nullptr;
}
const ScopeInfo3 * findInChildren(const std::string & scope) const {
for (const auto & child : children) {
if (child.type == Record && (child.name == scope || child.fullName == scope))