Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

enabled and fixed -Wuseless-cast GCC warnings #6930

Merged
merged 1 commit into from
Oct 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion cli/stacktrace.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ void print_stacktrace(FILE* output, int start_idx, bool demangling, int maxdepth
const char * const secondBracketAddress = strchr(firstBracketAddress, ']');
const char * const beginAddress = firstBracketAddress+3;
const int addressLen = int(secondBracketAddress-beginAddress);
const int padLen = int(ADDRESSDISPLAYLENGTH-addressLen);
const int padLen = (ADDRESSDISPLAYLENGTH-addressLen);
if (demangling && firstBracketName) {
const char * const plus = strchr(firstBracketName, '+');
if (plus && (plus>(firstBracketName+1))) {
Expand Down
1 change: 1 addition & 0 deletions cmake/compileroptions.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
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
add_compile_options_safe(-Wuseless-cast)
elseif(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
if(CMAKE_CXX_COMPILER_VERSION VERSION_EQUAL 14 OR CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 14)
# TODO: verify this regression still exists in clang-15
Expand Down
2 changes: 1 addition & 1 deletion gui/checkstatistics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -113,5 +113,5 @@ QStringList CheckStatistics::getTools() const
for (const QString& tool: mPerformance.keys()) ret.insert(tool);
for (const QString& tool: mPortability.keys()) ret.insert(tool);
for (const QString& tool: mError.keys()) ret.insert(tool);
return QStringList(ret.values());
return ret.values();
}
2 changes: 1 addition & 1 deletion gui/common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ QString toFilterString(const QMap<QString,QString>& filters, bool addAllSupporte

if (addAllSupported) {
entries << QCoreApplication::translate("toFilterString", "All supported files (%1)")
.arg(QStringList(filters.values()).join(" "));
.arg(filters.values().join(" "));
}

if (addAll) {
Expand Down
2 changes: 1 addition & 1 deletion gui/librarydialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,7 @@ QString LibraryDialog::getArgText(const CppcheckLibraryData::Function::Arg &arg)
s += "\n not uninit: " + QString(bool_to_string(arg.notuninit));
s += "\n format string: " + QString(bool_to_string(arg.formatstr));
s += "\n strz: " + QString(bool_to_string(arg.strz));
s += "\n valid: " + QString(arg.valid.isEmpty() ? "any" : arg.valid);
s += "\n valid: " + (arg.valid.isEmpty() ? "any" : arg.valid);
for (const CppcheckLibraryData::Function::Arg::MinSize &minsize : arg.minsizes) {
s += "\n minsize: " + minsize.type + " " + minsize.arg + " " + minsize.arg2;
}
Expand Down
2 changes: 1 addition & 1 deletion gui/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2018,7 +2018,7 @@ void MainWindow::editProjectFile()
if (!mProjectFile) {
QMessageBox msg(QMessageBox::Critical,
tr("Cppcheck"),
QString(tr("No project file loaded")),
tr("No project file loaded"),
QMessageBox::Ok,
this);
msg.exec();
Expand Down
2 changes: 1 addition & 1 deletion lib/checkclass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2189,7 +2189,7 @@ void CheckClass::checkConst()
std::string classname = scope->className;
const Scope *nest = scope->nestedIn;
while (nest && nest->type != Scope::eGlobal) {
classname = std::string(nest->className + "::" + classname);
classname = nest->className + "::" + classname;
nest = nest->nestedIn;
}

Expand Down
2 changes: 1 addition & 1 deletion lib/checkstl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,7 @@ void CheckStl::outOfBoundsIndexExpression()
void CheckStl::outOfBoundsIndexExpressionError(const Token *tok, const Token *index)
{
const std::string varname = tok ? tok->str() : std::string("var");
const std::string i = index ? index->expressionString() : std::string(varname + ".size()");
const std::string i = index ? index->expressionString() : (varname + ".size()");

std::string errmsg = "Out of bounds access of $symbol, index '" + i + "' is out of bounds.";

Expand Down
4 changes: 2 additions & 2 deletions lib/checkuninitvar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -467,7 +467,7 @@ bool CheckUninitVar::checkScopeForVariable(const Token *tok, const Variable& var
conditionAlwaysTrueOrFalse(tok->next()->astOperand2(), variableValue, &alwaysTrue, &alwaysFalse);

// initialization / usage in condition..
if (!alwaysTrue && checkIfForWhileHead(tok->next(), var, suppressErrors, bool(number_of_if == 0), *alloc, membervar))
if (!alwaysTrue && checkIfForWhileHead(tok->next(), var, suppressErrors, (number_of_if == 0), *alloc, membervar))
return true;

// checking if a not-zero variable is zero => bail out
Expand Down Expand Up @@ -643,7 +643,7 @@ bool CheckUninitVar::checkScopeForVariable(const Token *tok, const Variable& var
bool initcond = false;
if (!suppressErrors) {
const Token *startCond = forwhile ? tok->next() : tok->linkAt(1)->tokAt(2);
initcond = checkIfForWhileHead(startCond, var, false, bool(number_of_if == 0), *alloc, membervar);
initcond = checkIfForWhileHead(startCond, var, false, (number_of_if == 0), *alloc, membervar);
}

// goto "}"
Expand Down
2 changes: 2 additions & 0 deletions lib/json.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include "config.h"

SUPPRESS_WARNING_PUSH("-Wfloat-equal")
SUPPRESS_WARNING_GCC_PUSH("-Wuseless-cast")
SUPPRESS_WARNING_CLANG_PUSH("-Wtautological-type-limit-compare")
SUPPRESS_WARNING_CLANG_PUSH("-Wextra-semi-stmt")
SUPPRESS_WARNING_CLANG_PUSH("-Wzero-as-null-pointer-constant")
Expand All @@ -34,6 +35,7 @@ SUPPRESS_WARNING_CLANG_POP
SUPPRESS_WARNING_CLANG_POP
SUPPRESS_WARNING_CLANG_POP
SUPPRESS_WARNING_CLANG_POP
SUPPRESS_WARNING_GCC_POP
SUPPRESS_WARNING_POP

#endif // jsonH
4 changes: 4 additions & 0 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ if (BUILD_TESTS)
target_compile_definitions(testrunner PRIVATE CPPCHECKLIB_IMPORT SIMPLECPP_IMPORT)
target_link_libraries(testrunner cppcheck-core)
endif()
if (CMAKE_CXX_COMPILER_ID MATCHES "GNU")
# (void) in ASSERT_THROW* macros might trigger this
target_compile_options_safe(testrunner -Wno-useless-cast)
endif()
if (CMAKE_CXX_COMPILER_ID MATCHES "Clang")
# $ is used in dinit() designated initialization helper
target_compile_options_safe(testrunner -Wno-dollar-in-identifier-extension)
Expand Down
Loading