Remove useless casts reported by GCC with -Wuseless-cast option

This commit is contained in:
Yuriy Skalko 2021-09-29 12:49:21 +03:00
parent c52049bb83
commit d3c335a5d5
18 changed files with 33 additions and 35 deletions

View File

@ -1402,7 +1402,7 @@ docstring const BiblioInfo::getInfo(docstring const & key,
{ {
BiblioInfo::const_iterator it = find(key); BiblioInfo::const_iterator it = find(key);
if (it == end()) if (it == end())
return docstring(_("Bibliography entry not found!")); return _("Bibliography entry not found!");
BibTeXInfo const & data = it->second; BibTeXInfo const & data = it->second;
BibTeXInfoList xrefptrs; BibTeXInfoList xrefptrs;
for (docstring const & xref : getXRefs(data)) { for (docstring const & xref : getXRefs(data)) {

View File

@ -3827,7 +3827,7 @@ void Buffer::Impl::updateMacros(DocIterator & it, DocIterator & scope)
// FIXME (Abdel), I don't understand why we pass 'it' here // FIXME (Abdel), I don't understand why we pass 'it' here
// instead of 'macroTemplate' defined above... is this correct? // instead of 'macroTemplate' defined above... is this correct?
macros[macroTemplate.name()][it] = macros[macroTemplate.name()][it] =
Impl::ScopeMacro(scope, MacroData(const_cast<Buffer *>(owner_), it)); Impl::ScopeMacro(scope, MacroData(owner_, it));
} }
// next paragraph // next paragraph

View File

@ -853,7 +853,7 @@ Converters::RetVal Converters::runLaTeX(Buffer const & buffer, string const & co
// do the LaTeX run(s) // do the LaTeX run(s)
string const name = buffer.latexName(); string const name = buffer.latexName();
LaTeX latex(command, runparams, FileName(makeAbsPath(name)), LaTeX latex(command, runparams, makeAbsPath(name),
buffer.filePath(), buffer.layoutPos(), buffer.filePath(), buffer.layoutPos(),
buffer.isClone(), buffer.freshStartRequired()); buffer.isClone(), buffer.freshStartRequired());
TeXErrors terr; TeXErrors terr;

View File

@ -795,7 +795,7 @@ int LaTeX::scanLogFile(TeXErrors & terr)
string tmp = string tmp =
onlyFileName(changeExtension(file.absFileName(), ".log")); onlyFileName(changeExtension(file.absFileName(), ".log"));
LYXERR(Debug::LATEX, "Log file: " << tmp); LYXERR(Debug::LATEX, "Log file: " << tmp);
FileName const fn = FileName(makeAbsPath(tmp)); FileName const fn = makeAbsPath(tmp);
// FIXME we should use an ifdocstream here and a docstring for token // FIXME we should use an ifdocstream here and a docstring for token
// below. The encoding of the log file depends on the _output_ (font) // below. The encoding of the log file depends on the _output_ (font)
// encoding of the TeX file (T1, TU etc.). See #10728. // encoding of the TeX file (T1, TU etc.). See #10728.

View File

@ -69,7 +69,7 @@ ParIterator & ParIterator::operator--()
Paragraph & ParIterator::operator*() const Paragraph & ParIterator::operator*() const
{ {
return const_cast<Paragraph&>(text()->getPar(pit())); return text()->getPar(pit());
} }
@ -81,7 +81,7 @@ pit_type ParIterator::pit() const
Paragraph * ParIterator::operator->() const Paragraph * ParIterator::operator->() const
{ {
return const_cast<Paragraph*>(&text()->getPar(pit())); return &text()->getPar(pit());
} }
@ -93,7 +93,7 @@ pit_type ParIterator::outerPar() const
ParagraphList & ParIterator::plist() const ParagraphList & ParIterator::plist() const
{ {
return const_cast<ParagraphList&>(text()->paragraphs()); return text()->paragraphs();
} }

View File

@ -23,7 +23,7 @@ namespace{
QPalette::ColorRole role(ColorCode col) QPalette::ColorRole role(ColorCode col)
{ {
switch (ColorCode(col)) { switch (col) {
case Color_background: case Color_background:
case Color_commentbg: case Color_commentbg:
case Color_greyedoutbg: case Color_greyedoutbg:

View File

@ -172,7 +172,7 @@ void GuiBox::fillComboColor(QComboBox * combo, bool const is_none)
for (; cit != color_codes_.end(); ++cit) { for (; cit != color_codes_.end(); ++cit) {
QString const latexname = toqstr(lcolor.getLaTeXName(*cit)); QString const latexname = toqstr(lcolor.getLaTeXName(*cit));
QString const guiname = toqstr(translateIfPossible(lcolor.getGUIName(*cit))); QString const guiname = toqstr(translateIfPossible(lcolor.getGUIName(*cit)));
color = QColor(guiApp->colorCache().get(*cit, false)); color = guiApp->colorCache().get(*cit, false);
coloritem.fill(color); coloritem.fill(color);
combo->addItem(QIcon(coloritem), guiname, latexname); combo->addItem(QIcon(coloritem), guiname, latexname);
} }

View File

@ -1029,7 +1029,7 @@ GuiDocument::GuiDocument(GuiView & lv)
if (encvar.unsafe() ||encvar.guiName().empty() if (encvar.unsafe() ||encvar.guiName().empty()
|| utf8_base_encodings.contains(toqstr(encvar.name()))) || utf8_base_encodings.contains(toqstr(encvar.name())))
continue; continue;
if (std::string(encvar.name()).find("utf8") == 0) if (encvar.name().find("utf8") == 0)
encodingmap_utf8.insert(qt_(encvar.guiName()), toqstr(encvar.name())); encodingmap_utf8.insert(qt_(encvar.guiName()), toqstr(encvar.name()));
else else
encodingmap.insert(qt_(encvar.guiName()), toqstr(encvar.name())); encodingmap.insert(qt_(encvar.guiName()), toqstr(encvar.name()));
@ -5165,7 +5165,7 @@ GuiDocument::modInfoStruct GuiDocument::modInfo(LyXModule const & mod)
QString const guiname = toqstr(translateIfPossible(from_utf8(mod.getName()))); QString const guiname = toqstr(translateIfPossible(from_utf8(mod.getName())));
m.missingreqs = !isModuleAvailable(mod.getID()); m.missingreqs = !isModuleAvailable(mod.getID());
if (m.missingreqs) { if (m.missingreqs) {
m.name = QString(qt_("%1 (missing req.)")).arg(guiname); m.name = qt_("%1 (missing req.)").arg(guiname);
} else } else
m.name = guiname; m.name = guiname;
m.category = mod.category().empty() ? qt_("Miscellaneous") m.category = mod.category().empty() ? qt_("Miscellaneous")
@ -5178,7 +5178,7 @@ GuiDocument::modInfoStruct GuiDocument::modInfo(LyXModule const & mod)
desc.truncate(pos); desc.truncate(pos);
m.local = mod.isLocal(); m.local = mod.isLocal();
QString const mtype = m.local ? qt_("personal module") : qt_("distributed module"); QString const mtype = m.local ? qt_("personal module") : qt_("distributed module");
QString modulename = QString(qt_("<b>Module name:</b> <i>%1</i> (%2)")).arg(toqstr(m.id)).arg(mtype); QString modulename = qt_("<b>Module name:</b> <i>%1</i> (%2)").arg(toqstr(m.id)).arg(mtype);
// Tooltip is the desc followed by the module name and the type // Tooltip is the desc followed by the module name and the type
m.description = QString("%1%2") m.description = QString("%1%2")
.arg(desc.isEmpty() ? QString() : QString("<p>%1</p>").arg(desc), .arg(desc.isEmpty() ? QString() : QString("<p>%1</p>").arg(desc),

View File

@ -444,7 +444,7 @@ static void getSize(external::ResizeData & data,
data.scale = widgetToDoubleStr(&widthED); data.scale = widgetToDoubleStr(&widthED);
data.width = Length(); data.width = Length();
} else { } else {
data.width = Length(widgetsToLength(&widthED, &widthUnitCO)); data.width = widgetsToLength(&widthED, &widthUnitCO);
data.scale = string(); data.scale = string();
} }
data.height = Length(widgetsToLength(&heightED, &heightUnitCO)); data.height = Length(widgetsToLength(&heightED, &heightUnitCO));

View File

@ -101,7 +101,7 @@ GuiMathMatrix::GuiMathMatrix(GuiView & lv)
void GuiMathMatrix::columnsChanged(int) void GuiMathMatrix::columnsChanged(int)
{ {
int const nx = int(columnsSB->value()); int const nx = columnsSB->value();
halignED->setText(QString(nx, 'c')); halignED->setText(QString(nx, 'c'));
} }
@ -159,7 +159,7 @@ void GuiMathMatrix::slotOK()
// otherwise create just a standard AMS matrix // otherwise create just a standard AMS matrix
if (sh.contains('l') || sh.contains('r') || sh.contains('|')) { if (sh.contains('l') || sh.contains('r') || sh.contains('|')) {
string const str_ams = fromqstr( string const str_ams = fromqstr(
QString("%1 %2 %3").arg(int(1)).arg(int(1)).arg(deco_name)); QString("%1 %2 %3").arg(1).arg(1).arg(deco_name));
dispatch(FuncRequest(LFUN_MATH_AMS_MATRIX, str_ams)); dispatch(FuncRequest(LFUN_MATH_AMS_MATRIX, str_ams));
} else { } else {
string const str_ams = fromqstr( string const str_ams = fromqstr(

View File

@ -1153,7 +1153,7 @@ void PrefColors::applyRC(LyXRC & rc) const
void PrefColors::updateRC(LyXRC const & rc) void PrefColors::updateRC(LyXRC const & rc)
{ {
for (size_type i = 0; i < lcolors_.size(); ++i) { for (size_type i = 0; i < lcolors_.size(); ++i) {
QColor color = QColor(guiApp->colorCache().get(lcolors_[i], false)); QColor color = guiApp->colorCache().get(lcolors_[i], false);
QPixmap coloritem(32, 32); QPixmap coloritem(32, 32);
coloritem.fill(color); coloritem.fill(color);
lyxObjectsLW->item(int(i))->setIcon(QIcon(coloritem)); lyxObjectsLW->item(int(i))->setIcon(QIcon(coloritem));

View File

@ -112,7 +112,7 @@ bool GuiSendTo::isValid()
{ {
int const line = formatLW->currentRow(); int const line = formatLW->currentRow();
if (line < 0 || (line > int(formatLW->count()))) if (line < 0 || (line > formatLW->count()))
return false; return false;
return (!formatLW->selectedItems().empty() return (!formatLW->selectedItems().empty()

View File

@ -1182,7 +1182,7 @@ bool GuiView::prepareAllBuffersForLogout()
// We cannot use a for loop as the buffer list cycles. // We cannot use a for loop as the buffer list cycles.
Buffer * b = first; Buffer * b = first;
do { do {
if (!saveBufferIfNeeded(const_cast<Buffer &>(*b), false)) if (!saveBufferIfNeeded(*b, false))
return false; return false;
b = theBufferList().next(b); b = theBufferList().next(b);
} while (b != first); } while (b != first);
@ -3171,7 +3171,7 @@ bool GuiView::exportBufferAs(Buffer & b, docstring const & iformat)
return false; return false;
// fname is now the new Buffer location. // fname is now the new Buffer location.
if (FileName(fname).exists()) { if (fname.exists()) {
docstring const file = makeDisplayPath(fname.absFileName(), 30); docstring const file = makeDisplayPath(fname.absFileName(), 30);
docstring text = bformat(_("The document %1$s already " docstring text = bformat(_("The document %1$s already "
"exists.\n\nDo you want to " "exists.\n\nDo you want to "

View File

@ -1302,8 +1302,7 @@ void MenuDefinition::expandToc2(Toc const & toc_list,
label += QString::number(++shortcut_count); label += QString::number(++shortcut_count);
} }
} }
add(MenuItem(MenuItem::Command, label, add(MenuItem(MenuItem::Command, label, toc_list[i].action()));
FuncRequest(toc_list[i].action())));
// separator after the menu heading // separator after the menu heading
if (toc_list[i].depth() < depth) if (toc_list[i].depth() < depth)
add(MenuItem(MenuItem::Separator)); add(MenuItem(MenuItem::Separator));
@ -1331,8 +1330,7 @@ void MenuDefinition::expandToc2(Toc const & toc_list,
break; break;
} }
if (new_pos == pos + 1) { if (new_pos == pos + 1) {
add(MenuItem(MenuItem::Command, add(MenuItem(MenuItem::Command, label, toc_list[pos].action()));
label, FuncRequest(toc_list[pos].action())));
} else { } else {
MenuDefinition sub; MenuDefinition sub;
sub.expandToc2(toc_list, pos, new_pos, depth + 1, toc_type); sub.expandToc2(toc_list, pos, new_pos, depth + 1, toc_type);

View File

@ -742,7 +742,7 @@ string InsetGraphics::prepareFile(OutputParams const & runparams) const
if (from == to) { if (from == to) {
// source and destination formats are the same // source and destination formats are the same
if (!runparams.nice && !FileName(temp_file).hasExtension(ext)) { if (!runparams.nice && !temp_file.hasExtension(ext)) {
// The LaTeX compiler will not be able to determine // The LaTeX compiler will not be able to determine
// the file format from the extension, so we must // the file format from the extension, so we must
// change it. // change it.

View File

@ -287,7 +287,7 @@ int InsetIPADeco::plaintext(odocstringstream & os,
OutputParams const & runparams, size_t max_length) const OutputParams const & runparams, size_t max_length) const
{ {
odocstringstream ods; odocstringstream ods;
int h = (int)(InsetCollapsible::plaintext(ods, runparams, max_length) / 2); int h = InsetCollapsible::plaintext(ods, runparams, max_length) / 2;
docstring result = ods.str(); docstring result = ods.str();
docstring const before = result.substr(0, h); docstring const before = result.substr(0, h);
docstring const after = result.substr(h, result.size()); docstring const after = result.substr(h, result.size());
@ -311,7 +311,7 @@ void InsetIPADeco::docbook(XMLStream & xs, OutputParams const & runparams) const
// The special combining character must be put in the middle, between the two other characters. // The special combining character must be put in the middle, between the two other characters.
// It will not work if there is anything else than two pure characters, so going back to plaintext. // It will not work if there is anything else than two pure characters, so going back to plaintext.
odocstringstream ods; odocstringstream ods;
int h = (int)(InsetText::plaintext(ods, runparams) / 2); int h = InsetText::plaintext(ods, runparams) / 2;
docstring result = ods.str(); docstring result = ods.str();
docstring const before = result.substr(0, h); docstring const before = result.substr(0, h);
docstring const after = result.substr(h, result.size()); docstring const after = result.substr(h, result.size());

View File

@ -617,7 +617,7 @@ DocIterator separatorPos(InsetTableCell const * cell, docstring const & align_d)
InsetTableCell splitCell(InsetTableCell & head, docstring const & align_d, bool & hassep) InsetTableCell splitCell(InsetTableCell & head, docstring const & align_d, bool & hassep)
{ {
InsetTableCell tail = InsetTableCell(head); InsetTableCell tail = head;
DocIterator const dit = separatorPos(&head, align_d); DocIterator const dit = separatorPos(&head, align_d);
hassep = static_cast<bool>(dit); hassep = static_cast<bool>(dit);
if (hassep) { if (hassep) {
@ -839,13 +839,13 @@ void Tabular::appendRow(row_type row)
void Tabular::insertRow(row_type const row, bool copy) void Tabular::insertRow(row_type const row, bool copy)
{ {
row_info.insert(row_info.begin() + row + 1, RowData(row_info[row])); row_info.insert(row_info.begin() + row + 1, row_info[row]);
cell_info.insert(cell_info.begin() + row + 1, cell_info.insert(cell_info.begin() + row + 1,
cell_vector(0, CellData(buffer_))); cell_vector(0, CellData(buffer_)));
for (col_type c = 0; c < ncols(); ++c) { for (col_type c = 0; c < ncols(); ++c) {
cell_info[row + 1].insert(cell_info[row + 1].begin() + c, cell_info[row + 1].insert(cell_info[row + 1].begin() + c,
copy ? CellData(cell_info[row][c]) : CellData(buffer_)); copy ? cell_info[row][c] : CellData(buffer_));
if (cell_info[row][c].multirow == CELL_BEGIN_OF_MULTIROW) if (cell_info[row][c].multirow == CELL_BEGIN_OF_MULTIROW)
cell_info[row + 1][c].multirow = CELL_PART_OF_MULTIROW; cell_info[row + 1][c].multirow = CELL_PART_OF_MULTIROW;
} }
@ -1002,11 +1002,11 @@ void Tabular::appendColumn(col_type col)
void Tabular::insertColumn(col_type const col, bool copy) void Tabular::insertColumn(col_type const col, bool copy)
{ {
bool const ct = buffer().params().track_changes; bool const ct = buffer().params().track_changes;
column_info.insert(column_info.begin() + col + 1, ColumnData(column_info[col])); column_info.insert(column_info.begin() + col + 1, column_info[col]);
for (row_type r = 0; r < nrows(); ++r) { for (row_type r = 0; r < nrows(); ++r) {
cell_info[r].insert(cell_info[r].begin() + col + 1, cell_info[r].insert(cell_info[r].begin() + col + 1,
copy ? CellData(cell_info[r][col]) : CellData(buffer_)); copy ? cell_info[r][col] : CellData(buffer_));
if (cell_info[r][col].multicolumn == CELL_BEGIN_OF_MULTICOLUMN) if (cell_info[r][col].multicolumn == CELL_BEGIN_OF_MULTICOLUMN)
cell_info[r][col + 1].multicolumn = CELL_PART_OF_MULTICOLUMN; cell_info[r][col + 1].multicolumn = CELL_PART_OF_MULTICOLUMN;
} }
@ -4525,7 +4525,7 @@ void InsetTabular::metrics(MetricsInfo & mi, Dimension & dim) const
// determine horizontal offset because of decimal align (if necessary) // determine horizontal offset because of decimal align (if necessary)
int decimal_width = 0; int decimal_width = 0;
if (tabular.getAlignment(cell) == LYX_ALIGN_DECIMAL) { if (tabular.getAlignment(cell) == LYX_ALIGN_DECIMAL) {
InsetTableCell tail = InsetTableCell(*tabular.cellInset(cell)); InsetTableCell tail = *tabular.cellInset(cell);
tail.setBuffer(tabular.buffer()); tail.setBuffer(tabular.buffer());
// we need to set macrocontext position everywhere // we need to set macrocontext position everywhere
// otherwise we crash with nested insets (e.g. footnotes) // otherwise we crash with nested insets (e.g. footnotes)
@ -4778,7 +4778,7 @@ void InsetTabular::drawCellLines(PainterInfo & pi, int x, int y,
Color colour = Color_tabularline; Color colour = Color_tabularline;
if (tabular.column_info[col].change.changed() if (tabular.column_info[col].change.changed()
|| tabular.row_info[row].change.changed()) || tabular.row_info[row].change.changed())
colour = InsetTableCell(*tabular.cellInset(cell)).paragraphs().front().lookupChange(0).color(); colour = tabular.cellInset(cell)->paragraphs().front().lookupChange(0).color();
// Top // Top
bool drawline = tabular.topLine(cell) bool drawline = tabular.topLine(cell)
@ -6018,7 +6018,7 @@ bool InsetTabular::getStatus(Cursor & cur, FuncRequest const & cmd,
} }
// check if there is already a caption // check if there is already a caption
bool have_caption = false; bool have_caption = false;
InsetTableCell itc = InsetTableCell(*tabular.cellInset(cur.idx())); InsetTableCell itc = *tabular.cellInset(cur.idx());
ParagraphList::const_iterator pit = itc.paragraphs().begin(); ParagraphList::const_iterator pit = itc.paragraphs().begin();
ParagraphList::const_iterator pend = itc.paragraphs().end(); ParagraphList::const_iterator pend = itc.paragraphs().end();
for (; pit != pend; ++pit) { for (; pit != pend; ++pit) {

View File

@ -678,7 +678,7 @@ int InsetMathMacroTemplate::maxArgumentInDefinition() const
if (it.nextInset()->lyxCode() != MATH_MACROARG_CODE) if (it.nextInset()->lyxCode() != MATH_MACROARG_CODE)
continue; continue;
InsetMathMacroArgument * arg = static_cast<InsetMathMacroArgument*>(it.nextInset()); InsetMathMacroArgument * arg = static_cast<InsetMathMacroArgument*>(it.nextInset());
maxArg = std::max(int(arg->number()), maxArg); maxArg = std::max(arg->number(), maxArg);
} }
return maxArg; return maxArg;
} }