Skip to content

Commit f78e5a7

Browse files
authored
enabled and fixed -Wold-style-cast Clang warnings (#7395)
1 parent 610386c commit f78e5a7

36 files changed

+133
-132
lines changed

cli/signalhandler.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -116,9 +116,9 @@ static void CppcheckSignalHandler(int signo, siginfo_t * info, void * context)
116116
// TODO: separate these two defines
117117
#if defined(__linux__) && defined(REG_ERR)
118118
const auto* const uc = reinterpret_cast<const ucontext_t*>(context);
119-
killid = (pid_t) syscall(SYS_gettid);
119+
killid = static_cast<pid_t>(syscall(SYS_gettid));
120120
if (uc) {
121-
type = (int)uc->uc_mcontext.gregs[REG_ERR] & 2;
121+
type = static_cast<int>(uc->uc_mcontext.gregs[REG_ERR]) & 2;
122122
}
123123
#else
124124
(void)context;
@@ -170,7 +170,7 @@ static void CppcheckSignalHandler(int signo, siginfo_t * info, void * context)
170170
break;
171171
}
172172
fprintf(output, " (at 0x%lx).\n",
173-
(unsigned long)info->si_addr);
173+
reinterpret_cast<unsigned long>(info->si_addr));
174174
break;
175175
case SIGFPE:
176176
fputs("Internal error: cppcheck received signal ", output);
@@ -204,7 +204,7 @@ static void CppcheckSignalHandler(int signo, siginfo_t * info, void * context)
204204
break;
205205
}
206206
fprintf(output, " (at 0x%lx).\n",
207-
(unsigned long)info->si_addr);
207+
reinterpret_cast<unsigned long>(info->si_addr));
208208
break;
209209
case SIGILL:
210210
fputs("Internal error: cppcheck received signal ", output);
@@ -238,7 +238,7 @@ static void CppcheckSignalHandler(int signo, siginfo_t * info, void * context)
238238
break;
239239
}
240240
fprintf(output, " (at 0x%lx).%s\n",
241-
(unsigned long)info->si_addr,
241+
reinterpret_cast<unsigned long>(info->si_addr),
242242
(isAddressOnStack)?" Stackoverflow?":"");
243243
break;
244244
case SIGINT:
@@ -264,7 +264,7 @@ static void CppcheckSignalHandler(int signo, siginfo_t * info, void * context)
264264
// cppcheck-suppress knownConditionTrueFalse ; FP
265265
(type==-1)? "" :
266266
(type==0) ? "reading " : "writing ",
267-
(unsigned long)info->si_addr,
267+
reinterpret_cast<unsigned long>(info->si_addr),
268268
(isAddressOnStack)?" Stackoverflow?":""
269269
);
270270
break;

cli/stacktrace.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ void print_stacktrace(FILE* output, int start_idx, bool demangling, int maxdepth
3333
// 32 vs. 64bit
3434
#define ADDRESSDISPLAYLENGTH ((sizeof(long)==8)?12:8)
3535
void *callstackArray[32]= {nullptr}; // the less resources the better...
36-
const int currentdepth = backtrace(callstackArray, (int)getArrayLength(callstackArray));
36+
const int currentdepth = backtrace(callstackArray, static_cast<int>(getArrayLength(callstackArray)));
3737
// set offset to 1 to omit the printing function itself
3838
int offset=start_idx+1; // some entries on top are within our own exception handling code or libc
3939
if (maxdepth<0)
@@ -86,12 +86,12 @@ void print_stacktrace(FILE* output, int start_idx, bool demangling, int maxdepth
8686
padLen, 0);
8787
if (realnameString) {
8888
fprintf(output, "%.*s in %s\n",
89-
(int)(secondBracketAddress-firstBracketAddress-3), firstBracketAddress+3,
89+
static_cast<int>(secondBracketAddress - firstBracketAddress - 3), firstBracketAddress+3,
9090
realnameString);
9191
} else {
9292
fprintf(output, "%.*s in %.*s\n",
93-
(int)(secondBracketAddress-firstBracketAddress-3), firstBracketAddress+3,
94-
(int)(firstBracketAddress-symbolString), symbolString);
93+
static_cast<int>(secondBracketAddress - firstBracketAddress - 3), firstBracketAddress+3,
94+
static_cast<int>(firstBracketAddress - symbolString), symbolString);
9595
}
9696
}
9797
// NOLINTNEXTLINE(bugprone-multi-level-implicit-pointer-conversion) - code matches the documented usage

cmake/compileroptions.cmake

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,6 @@ elseif(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
108108
# TODO: fix and enable these warnings - or move to suppression list below
109109
add_compile_options_safe(-Wno-documentation-unknown-command) # TODO: Clang currently does not support all commands
110110
add_compile_options_safe(-Wno-unused-exception-parameter)
111-
add_compile_options_safe(-Wno-old-style-cast)
112111
add_compile_options_safe(-Wno-sign-conversion)
113112
add_compile_options_safe(-Wno-shadow-field-in-constructor)
114113
add_compile_options_safe(-Wno-covered-switch-default)

gui/codeeditor.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -425,8 +425,8 @@ void CodeEditor::lineNumberAreaPaintEvent(const QPaintEvent *event)
425425

426426
QTextBlock block = firstVisibleBlock();
427427
int blockNumber = block.blockNumber();
428-
int top = (int) blockBoundingGeometry(block).translated(contentOffset()).top();
429-
int bottom = top + (int) blockBoundingRect(block).height();
428+
int top = static_cast<int>(blockBoundingGeometry(block).translated(contentOffset()).top());
429+
int bottom = top + static_cast<int>(blockBoundingRect(block).height());
430430

431431
while (block.isValid() && top <= event->rect().bottom()) {
432432
if (block.isVisible() && bottom >= event->rect().top()) {
@@ -438,7 +438,7 @@ void CodeEditor::lineNumberAreaPaintEvent(const QPaintEvent *event)
438438

439439
block = block.next();
440440
top = bottom;
441-
bottom = top + (int) blockBoundingRect(block).height();
441+
bottom = top + static_cast<int>(blockBoundingRect(block).height());
442442
++blockNumber;
443443
}
444444
}

gui/compliancereportdialog.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ void ComplianceReportDialog::save()
197197
QCryptographicHash hash(QCryptographicHash::Algorithm::Md5);
198198
if (hash.addData(&f)) {
199199
for (auto b: hash.result())
200-
out << QString::number((unsigned char)b,16);
200+
out << QString::number(static_cast<unsigned char>(b),16);
201201
out << " " << fileName << "\n";
202202
}
203203
}

gui/librarydialog.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -313,7 +313,7 @@ void LibraryDialog::changeFunction()
313313
return;
314314

315315
function->comments = mUi->comments->toPlainText();
316-
function->noreturn = (CppcheckLibraryData::Function::TrueFalseUnknown)mUi->noreturn->currentIndex();
316+
function->noreturn = static_cast<CppcheckLibraryData::Function::TrueFalseUnknown>(mUi->noreturn->currentIndex());
317317
function->useretval = mUi->useretval->isChecked();
318318
function->leakignore = mUi->leakignore->isChecked();
319319

gui/mainwindow.cpp

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -309,7 +309,7 @@ MainWindow::MainWindow(TranslationHandler* th, QSettings* settings) :
309309
#else
310310
constexpr Platform::Type defaultPlatform = Platform::Type::Unspecified;
311311
#endif
312-
PlatformData &platform = mPlatforms.get((Platform::Type)mSettings->value(SETTINGS_CHECKED_PLATFORM, defaultPlatform).toInt());
312+
PlatformData &platform = mPlatforms.get(static_cast<Platform::Type>(mSettings->value(SETTINGS_CHECKED_PLATFORM, defaultPlatform).toInt()));
313313
platform.mActMainWindow->setChecked(true);
314314

315315
mNetworkAccessManager = new QNetworkAccessManager(this);
@@ -385,7 +385,7 @@ void MainWindow::loadSettings()
385385
mSettings->value(SETTINGS_WINDOW_HEIGHT, 600).toInt());
386386
}
387387

388-
const ReportType reportType = (ReportType)mSettings->value(SETTINGS_REPORT_TYPE, (int)ReportType::normal).toInt();
388+
const ReportType reportType = static_cast<ReportType>(mSettings->value(SETTINGS_REPORT_TYPE, static_cast<int>(ReportType::normal)).toInt());
389389
mUI->mActionReportNormal->setChecked(reportType <= ReportType::normal);
390390
mUI->mActionReportAutosar->setChecked(reportType == ReportType::autosar);
391391
mUI->mActionReportCertC->setChecked(reportType == ReportType::certC);
@@ -433,7 +433,7 @@ void MainWindow::loadSettings()
433433
mUI->mActionToolBarFilter->setChecked(showFilterToolbar);
434434
mUI->mToolBarFilter->setVisible(showFilterToolbar);
435435

436-
const Standards::Language enforcedLanguage = (Standards::Language)mSettings->value(SETTINGS_ENFORCED_LANGUAGE, 0).toInt();
436+
const Standards::Language enforcedLanguage = static_cast<Standards::Language>(mSettings->value(SETTINGS_ENFORCED_LANGUAGE, 0).toInt());
437437
if (enforcedLanguage == Standards::Language::CPP)
438438
mUI->mActionEnforceCpp->setChecked(true);
439439
else if (enforcedLanguage == Standards::Language::C)
@@ -483,7 +483,7 @@ void MainWindow::saveSettings() const
483483
mUI->mActionReportMisraCpp2008->isChecked() ? ReportType::misraCpp2008 :
484484
mUI->mActionReportMisraCpp2023->isChecked() ? ReportType::misraCpp2023 :
485485
ReportType::normal;
486-
mSettings->setValue(SETTINGS_REPORT_TYPE, (int)reportType);
486+
mSettings->setValue(SETTINGS_REPORT_TYPE, static_cast<int>(reportType));
487487

488488
// Show * states
489489
mSettings->setValue(SETTINGS_SHOW_STYLE, mUI->mActionShowStyle->isChecked());
@@ -559,7 +559,7 @@ void MainWindow::doAnalyzeProject(ImportProject p, const bool checkLibrary, cons
559559
p.ignorePaths(v);
560560

561561
if (!mProjectFile->getAnalyzeAllVsConfigs()) {
562-
const Platform::Type platform = (Platform::Type) mSettings->value(SETTINGS_CHECKED_PLATFORM, 0).toInt();
562+
const Platform::Type platform = static_cast<Platform::Type>(mSettings->value(SETTINGS_CHECKED_PLATFORM, 0).toInt());
563563
std::vector<std::string> configurations;
564564
const QStringList configs = mProjectFile->getVsConfigurations();
565565
std::transform(configs.cbegin(), configs.cend(), std::back_inserter(configurations), [](const QString& e) {
@@ -1125,7 +1125,7 @@ bool MainWindow::getCppcheckSettings(Settings& settings, Suppressions& supprs)
11251125
settings.platform.loadFromFile(applicationFilePath.toStdString().c_str(), platform.toStdString());
11261126
} else {
11271127
for (int i = Platform::Type::Native; i <= Platform::Type::Unix64; i++) {
1128-
const auto p = (Platform::Type)i;
1128+
const auto p = static_cast<Platform::Type>(i);
11291129
if (platform == Platform::toString(p)) {
11301130
settings.platform.set(p);
11311131
break;
@@ -1205,10 +1205,10 @@ bool MainWindow::getCppcheckSettings(Settings& settings, Suppressions& supprs)
12051205
settings.jobs = mSettings->value(SETTINGS_CHECK_THREADS, 1).toInt();
12061206
settings.certainty.setEnabled(Certainty::inconclusive, mSettings->value(SETTINGS_INCONCLUSIVE_ERRORS, false).toBool());
12071207
if (!mProjectFile || settings.platform.type == Platform::Type::Unspecified)
1208-
settings.platform.set((Platform::Type) mSettings->value(SETTINGS_CHECKED_PLATFORM, 0).toInt());
1208+
settings.platform.set(static_cast<Platform::Type>(mSettings->value(SETTINGS_CHECKED_PLATFORM, 0).toInt()));
12091209
settings.standards.setCPP(mSettings->value(SETTINGS_STD_CPP, QString()).toString().toStdString());
12101210
settings.standards.setC(mSettings->value(SETTINGS_STD_C, QString()).toString().toStdString());
1211-
settings.enforcedLang = (Standards::Language)mSettings->value(SETTINGS_ENFORCED_LANGUAGE, 0).toInt();
1211+
settings.enforcedLang = static_cast<Standards::Language>(mSettings->value(SETTINGS_ENFORCED_LANGUAGE, 0).toInt());
12121212

12131213
settings.jobs = std::max(settings.jobs, 1u);
12141214

@@ -2133,7 +2133,7 @@ void MainWindow::updateMRUMenuItems()
21332133
if (removed)
21342134
mSettings->setValue(SETTINGS_MRU_PROJECTS, projects);
21352135

2136-
const int numRecentProjects = qMin(projects.size(), (int)MaxRecentProjects);
2136+
const int numRecentProjects = qMin(projects.size(), static_cast<int>(MaxRecentProjects));
21372137
for (int i = 0; i < numRecentProjects; i++) {
21382138
const QString filename = QFileInfo(projects[i]).fileName();
21392139
const QString text = QString("&%1 %2").arg(i + 1).arg(filename);
@@ -2172,7 +2172,7 @@ void MainWindow::selectPlatform()
21722172
{
21732173
auto *action = qobject_cast<QAction *>(sender());
21742174
if (action) {
2175-
const Platform::Type platform = (Platform::Type) action->data().toInt();
2175+
const Platform::Type platform = static_cast<Platform::Type>(action->data().toInt());
21762176
mSettings->setValue(SETTINGS_CHECKED_PLATFORM, platform);
21772177
}
21782178
}

gui/resultstree.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1006,7 +1006,7 @@ void ResultsTree::copy()
10061006
QString inconclusive = itemdata[INCONCLUSIVE].toBool() ? ",inconclusive" : "";
10071007
text += itemdata[FILENAME].toString() + ':' + QString::number(itemdata[LINE].toInt()) + ':' + QString::number(itemdata[COLUMN].toInt())
10081008
+ ": "
1009-
+ QString::fromStdString(severityToString(ShowTypes::ShowTypeToSeverity((ShowTypes::ShowType)itemdata[SEVERITY].toInt()))) + inconclusive
1009+
+ QString::fromStdString(severityToString(ShowTypes::ShowTypeToSeverity(static_cast<ShowTypes::ShowType>(itemdata[SEVERITY].toInt())))) + inconclusive
10101010
+ ": "
10111011
+ itemdata[MESSAGE].toString()
10121012
+ " ["

gui/showtypes.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ ShowTypes::ShowType ShowTypes::VariantToShowType(const QVariant &data)
8989
if (value < ShowTypes::ShowStyle || value > ShowTypes::ShowErrors) {
9090
return ShowTypes::ShowNone;
9191
}
92-
return (ShowTypes::ShowType)value;
92+
return static_cast<ShowTypes::ShowType>(value);
9393
}
9494

9595
void ShowTypes::load()

gui/statsdialog.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ void StatsDialog::pdfExport()
199199
.arg(tr("Information messages"))
200200
.arg(mStatistics->getCount(CPPCHECK,ShowTypes::ShowInformation));
201201

202-
QString fileName = QFileDialog::getSaveFileName((QWidget*)nullptr, tr("Export PDF"), QString(), "*.pdf");
202+
QString fileName = QFileDialog::getSaveFileName(nullptr, tr("Export PDF"), QString(), "*.pdf");
203203
if (QFileInfo(fileName).suffix().isEmpty()) {
204204
fileName.append(".pdf");
205205
}

0 commit comments

Comments
 (0)