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

Dantti/clang fixes #373

Merged
merged 1 commit into from
Dec 30, 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
11 changes: 11 additions & 0 deletions .clang-tidy
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# This is a generated file do not edit but instead edit .clang-tidy.checks and .clang-tidy.settings

Checks: '*,-abseil*,-altera-*,-android-*,-boost-*,-cppcoreguidelines-*,-darwin-*,-fuchsia-*,-hicpp-*,-llvmlibc-*,-linuxkernel-*,-mpi-*,-objc-*,-openmp-*,-zircon-*,-bugprone-unchecked-optional-access,-bugprone-narrowing-conversions,-bugprone-easily-swappable-parameters,-bugprone-branch-clone,-bugprone-implicit-widening-of-multiplication-result,-bugprone-suspicious-include,-bugprone-integer-division,-bugprone-suspicious-enum-usage,-cert-err58-cpp,-cert-dcl21-cpp,-cert-dcl50-cpp,-clang-analyzer-alpha*,-clang-analyzer-osx.*,-clang-analyzer-webkit.*,-clang-analyzer-cplusplus.NewDeleteLeaks,-clang-analyzer-core.CallAndMessage,-clang-analyzer-alpha.core.CastToStruct,-clang-analyzer-alpha.deadcode.UnreachableCode,-clang-analyzer-core.NonNullParamChecker,-concurrency-*,-clang-diagnostic-pragma-once-outside-header,-google-*,google-explicit-constructor,google-readability-namespace-comments,-llvm-include-order,-llvm-namespace-comment,-llvm-qualified-auto,-llvm-else-after-return,-llvm-header-guard,-misc-no-recursion,-misc-non-private-member-variables-in-classes,-misc-const-correctness,-misc-include-cleaner,-modernize-use-override,-modernize-use-bool-literals,-modernize-pass-by-value,-modernize-raw-string-literal,-modernize-use-using,-modernize-loop-convert,-modernize-return-braced-init-list,-modernize-use-equals-default,-modernize-use-trailing-return-type,-modernize-use-nodiscard,-modernize-avoid-bind,-modernize-avoid-c-arrays,-modernize-type-traits,-performance-unnecessary-copy-initialization,-performance-no-automatic-move,-performance-no-int-to-ptr,-performance-enum-size,-readability-else-after-return,-readability-named-parameter,-readability-implicit-bool-conversion,-readability-namespace-comments,-readability-qualified-auto,-readability-magic-numbers,-readability-braces-around-statements,-readability-function-cognitive-complexity,-readability-const-return-type,-readability-inconsistent-declaration-parameter-name,-readability-simplify-boolean-expr,-readability-redundant-access-specifiers,-readability-identifier-length,-readability-misleading-indentation,-readability-make-member-function-const,-readability-suspicious-call-argument,-readability-avoid-nested-conditional-operator,-clang-analyzer-security.insecureAPI.*,-performance-unnecessary-value-param,-readability-convert-member-functions-to-static,-bugprone-misplaced-widening-cast,'

CheckOptions:
- key: cppcoreguidelines-special-member-functions.AllowSoleDefaultDtor
value: 1
- key: cppcoreguidelines-special-member-functions.AllowMissingMoveFunctionsWhenCopyIsDeleted
value: 1
- key: performance-move-const-arg.CheckTriviallyCopyableMove
value: 0
105 changes: 105 additions & 0 deletions .clang-tidy.checks
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
# I want all checks by default. That way I'll have to black list new checks rather than whitelist them
*

-abseil* # Try
-altera-*
-android-*
-boost-*
-cppcoreguidelines-* # Try
-darwin-*
-fuchsia-*
-hicpp-* # Tryu
-llvmlibc-*
-linuxkernel-*
-mpi-*
-objc-*
-openmp-*
-zircon-*

-bugprone-unchecked-optional-access # https://github.com/llvm/llvm-project/issues/55530
-bugprone-narrowing-conversions
-bugprone-easily-swappable-parameters
-bugprone-branch-clone
-bugprone-implicit-widening-of-multiplication-result
-bugprone-suspicious-include # This one doesn't like us importing moc_XXX.cpp files
-bugprone-integer-division
-bugprone-suspicious-enum-usage # in Qt5 this complains about Qt::CTRL | Qt::Key_a which is the right way to do it in Qt6

-cert-err58-cpp
-cert-dcl21-cpp

# I only use this when I ignore the parameters altogether (See ContactsPage.cpp e.g)
-cert-dcl50-cpp

-clang-analyzer-alpha*
-clang-analyzer-osx.*
-clang-analyzer-webkit.*
-clang-analyzer-cplusplus.NewDeleteLeaks
-clang-analyzer-core.CallAndMessage
-clang-analyzer-alpha.core.CastToStruct
-clang-analyzer-alpha.deadcode.UnreachableCode
-clang-analyzer-core.NonNullParamChecker

-concurrency-*

# This gives false possitive in all header files.
-clang-diagnostic-pragma-once-outside-header

-google-* # Try
google-explicit-constructor
google-readability-namespace-comments

-llvm-include-order
-llvm-namespace-comment
-llvm-qualified-auto
-llvm-else-after-return
-llvm-header-guard # complains even though we have #pragma once

-misc-no-recursion
-misc-non-private-member-variables-in-classes # I agree instance variables should be private, but often I do this by design - too noisy.
-misc-const-correctness # Lots of hits, lets ignore it for now.
-misc-include-cleaner # Completely broken as of Oct 2023

-modernize-use-override
-modernize-use-bool-literals
-modernize-pass-by-value
-modernize-raw-string-literal
-modernize-use-using
-modernize-loop-convert
-modernize-return-braced-init-list
-modernize-use-equals-default
-modernize-use-trailing-return-type
-modernize-use-nodiscard
-modernize-avoid-bind
-modernize-avoid-c-arrays
-modernize-type-traits # Lots of errors from QTestLib

-performance-unnecessary-copy-initialization
-performance-no-automatic-move # often doesn't do much of a difference in Qt apps, due to their ref counting.
-performance-no-int-to-ptr
-performance-enum-size # int is faster than int8_t

-readability-else-after-return
-readability-named-parameter
-readability-implicit-bool-conversion # Lots of warnings about if (myPointer) -> if (myPointer != nullptr)
-readability-namespace-comments
-readability-qualified-auto
-readability-magic-numbers
-readability-braces-around-statements
-readability-function-cognitive-complexity
-readability-const-return-type
-readability-inconsistent-declaration-parameter-name
-readability-simplify-boolean-expr
-readability-redundant-access-specifiers
-readability-identifier-length
-readability-misleading-indentation
-readability-make-member-function-const # complains about functions updating pointers too
-readability-suspicious-call-argument
-readability-avoid-nested-conditional-operator # I simply do not agree that this is hard to read, esp with clang-format formatting it nicely

-clang-analyzer-security.insecureAPI.*

# Try all the rest in this file
-performance-unnecessary-value-param
-readability-convert-member-functions-to-static
-bugprone-misplaced-widening-cast
7 changes: 7 additions & 0 deletions .clang-tidy.settings
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
CheckOptions:
- key: cppcoreguidelines-special-member-functions.AllowSoleDefaultDtor
value: 1
- key: cppcoreguidelines-special-member-functions.AllowMissingMoveFunctionsWhenCopyIsDeleted
value: 1
- key: performance-move-const-arg.CheckTriviallyCopyableMove
value: 0
2 changes: 1 addition & 1 deletion QXlsx/header/xlsxdocument.h
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ class QXLSX_EXPORT Document : public QObject
bool autosizeColumnWidth(const CellRange &range);
bool autosizeColumnWidth(int column);
bool autosizeColumnWidth(int colFirst, int colLast);
bool autosizeColumnWidth(void);
bool autosizeColumnWidth();

private:
QMap<int, int> getMaximalColumnWidth(int firstRow = 1, int lastRow = INT_MAX);
Expand Down
2 changes: 1 addition & 1 deletion QXlsx/header/xlsxworksheet.h
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ class QXLSX_EXPORT Worksheet : public AbstractSheet
void setWhiteSpaceVisible(bool visible);
bool setStartPage(int spagen); // add by liufeijin20181028

QVector<CellLocation> getFullCells(int *maxRow, int *maxCol);
QVector<CellLocation> getFullCells(int *maxRow, int *maxCol) const;

private:
void saveToXmlFile(QIODevice *device) const override;
Expand Down
3 changes: 1 addition & 2 deletions QXlsx/source/xlsxcell.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,7 @@ Cell::Cell(const Cell *const cell)
*/
Cell::~Cell()
{
if (nullptr != d_ptr)
delete d_ptr;
delete d_ptr;
}

/*!
Expand Down
5 changes: 4 additions & 1 deletion QXlsx/source/xlsxcellformula.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,10 @@ CellFormula::CellFormula(const CellFormula &other)
*/
CellFormula &CellFormula::operator=(const CellFormula &other)
{
d = other.d;
if (this != &other) // Self-assignment check [cert-oop54-cpp]
{
this->d = other.d;
}
return *this;
}

Expand Down
19 changes: 0 additions & 19 deletions QXlsx/source/xlsxchart.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1168,25 +1168,6 @@ void ChartPrivate::saveXmlSer(QXmlStreamWriter &writer, XlsxSeries *ser, int id)
writer.writeEndElement();
}

#if 0
if (!ser->axDataSource_numRef.isEmpty())
{
if (chartType == Chart::CT_ScatterChart || chartType == Chart::CT_BubbleChart)
{
writer.writeStartElement(QStringLiteral("c:xVal"));
}
else
{
writer.writeStartElement(QStringLiteral("c:cat"));
}

writer.writeStartElement(QStringLiteral("c:numRef"));
writer.writeTextElement(QStringLiteral("c:f"), ser->axDataSource_numRef);
writer.writeEndElement();//c:numRef
writer.writeEndElement();//c:cat or c:xVal
}
#endif

if (!ser->numberDataSource_numRef.isEmpty()) {
if (chartType == Chart::CT_ScatterChart || chartType == Chart::CT_BubbleChart)
writer.writeStartElement(QStringLiteral("c:yVal"));
Expand Down
3 changes: 1 addition & 2 deletions QXlsx/source/xlsxchartsheet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,7 @@ Chartsheet::Chartsheet(const QString &name, int id, Workbook *workbook, CreateFl
if (flag == Chartsheet::F_NewFromScratch) {
d_func()->drawing = std::make_shared<Drawing>(this, flag);

DrawingAbsoluteAnchor *anchor =
new DrawingAbsoluteAnchor(drawing(), DrawingAnchor::Picture);
auto anchor = new DrawingAbsoluteAnchor(drawing(), DrawingAnchor::Picture);

anchor->pos = QPoint(0, 0);
anchor->ext = QSize(9293679, 6068786);
Expand Down
13 changes: 9 additions & 4 deletions QXlsx/source/xlsxconditionalformatting.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,10 @@ ConditionalFormatting::ConditionalFormatting(const ConditionalFormatting &other)
*/
ConditionalFormatting &ConditionalFormatting::operator=(const ConditionalFormatting &other)
{
this->d = other.d;
if (this != &other) // Self-assignment check [cert-oop54-cpp]
{
this->d = other.d;
}
return *this;
}

Expand Down Expand Up @@ -786,9 +789,11 @@ bool ConditionalFormatting::saveToXml(QXmlStreamWriter &writer) const
writer.writeTextElement(QStringLiteral("formula"),
it.value().toString().arg(startCell));
}
} else if ((it = rule->attrs.constFind(XlsxCfRuleData::A_formula1)) !=
rule->attrs.constEnd()) {
writer.writeTextElement(QStringLiteral("formula"), it.value().toString());
} else {
it = rule->attrs.constFind(XlsxCfRuleData::A_formula1);
if (it != rule->attrs.constEnd()) {
writer.writeTextElement(QStringLiteral("formula"), it.value().toString());
}
}

it = rule->attrs.constFind(XlsxCfRuleData::A_formula2);
Expand Down
5 changes: 4 additions & 1 deletion QXlsx/source/xlsxdatavalidation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,10 @@ DataValidation::DataValidation(const DataValidation &other)
*/
DataValidation &DataValidation::operator=(const DataValidation &other)
{
this->d = other.d;
if (this != &other) // Self-assignment check [cert-oop54-cpp]
{
this->d = other.d;
}
return *this;
}

Expand Down
10 changes: 5 additions & 5 deletions QXlsx/source/xlsxdocument.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,8 @@ std::string copyTag(const std::string &sFrom, const std::string &sTo, const std:
const std::string tagEnd = "</" + tag + ">";

// search all occurrences of tag in 'sFrom'
std::string sFromData = "";
size_t startIndex = 0;
std::string sFromData;
size_t startIndex = 0;
while (true) {
std::size_t startPos = sFrom.find(tagToFindStart, startIndex);
if (startPos != std::string::npos) {
Expand Down Expand Up @@ -491,7 +491,7 @@ bool DocumentPrivate::saveCsv(QString mainCSVFileName) const

currentSheet->workbook()->setActiveSheet(sheetIndexNumber);

Worksheet *wsheet = static_cast<Worksheet *>(currentSheet->workbook()->activeSheet());
auto wsheet = static_cast<Worksheet *>(currentSheet->workbook()->activeSheet());
if (wsheet == nullptr) {
continue;
}
Expand Down Expand Up @@ -572,7 +572,7 @@ bool DocumentPrivate::copyStyle(const QString &from, const QString &to)
ZipReader zipReader(from);
QStringList filePaths = zipReader.filePaths();

std::shared_ptr<ZipReader> toReader = std::shared_ptr<ZipReader>(new ZipReader(to));
auto toReader = std::make_shared<ZipReader>(to);

QStringList toFilePaths = toReader->filePaths();

Expand Down Expand Up @@ -1539,7 +1539,7 @@ bool Document::autosizeColumnWidth(int colFirst, int colLast)
Auto sets width in characters for all columns.
Returns true on success.
*/
bool Document::autosizeColumnWidth(void)
bool Document::autosizeColumnWidth()
{
bool erg = false;

Expand Down
8 changes: 6 additions & 2 deletions QXlsx/source/xlsxnumformatparser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,12 @@ bool NumFormatParser::isDateTime(const QString &formatCode)

// quoted plain text block: don't care, ignore
case '"':
while (i < formatCode.length() - 1 && formatCode[++i] != QLatin1Char('"'))
;
while (i < formatCode.length() - 1) {
++i;
if (formatCode[i] == QLatin1Char('"')) {
break;
}
}
break;

// escaped char: don't care, ignore
Expand Down
32 changes: 17 additions & 15 deletions QXlsx/source/xlsxstyles.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -148,24 +148,26 @@ void Styles::fixNumFmt(const Format &format)

const auto &str = format.numberFormat();
if (!str.isEmpty()) {
QHash<QString, std::shared_ptr<XlsxFormatNumberData>>::ConstIterator cIt;
// Assign proper number format index
const auto &it = m_builtinNumFmtsHash.constFind(str);
if (it != m_builtinNumFmtsHash.constEnd()) {
const_cast<Format *>(&format)->fixNumberFormat(it.value(), str);
} else if ((cIt = m_customNumFmtsHash.constFind(str)) != m_customNumFmtsHash.constEnd()) {
const_cast<Format *>(&format)->fixNumberFormat(cIt.value()->formatIndex, str);
} else {
// Assign a new fmt Id.
const_cast<Format *>(&format)->fixNumberFormat(m_nextCustomNumFmtId, str);

auto fmt = std::make_shared<XlsxFormatNumberData>();
fmt->formatIndex = m_nextCustomNumFmtId;
fmt->formatString = str;
m_customNumFmtIdMap.insert(m_nextCustomNumFmtId, fmt);
m_customNumFmtsHash.insert(str, fmt);

m_nextCustomNumFmtId += 1;
auto cIt = m_customNumFmtsHash.constFind(str);
if (cIt != m_customNumFmtsHash.constEnd()) {
const_cast<Format *>(&format)->fixNumberFormat(cIt.value()->formatIndex, str);
} else {
// Assign a new fmt Id.
const_cast<Format *>(&format)->fixNumberFormat(m_nextCustomNumFmtId, str);

auto fmt = std::make_shared<XlsxFormatNumberData>();
fmt->formatIndex = m_nextCustomNumFmtId;
fmt->formatString = str;
m_customNumFmtIdMap.insert(m_nextCustomNumFmtId, fmt);
m_customNumFmtsHash.insert(str, fmt);

m_nextCustomNumFmtId += 1;
}
}
} else {
const auto id = format.numberFormatIndex();
Expand Down Expand Up @@ -350,7 +352,7 @@ void Styles::saveToXmlFile(QIODevice *device) const

void Styles::writeNumFmts(QXmlStreamWriter &writer) const
{
if (m_customNumFmtIdMap.size() == 0)
if (m_customNumFmtIdMap.isEmpty())
return;

writer.writeStartElement(QStringLiteral("numFmts"));
Expand Down Expand Up @@ -433,7 +435,7 @@ void Styles::writeFont(QXmlStreamWriter &writer, const Format &format, bool isDx
}

if (format.hasProperty(FormatPrivate::P_Font_Color)) {
XlsxColor color = format.property(FormatPrivate::P_Font_Color).value<XlsxColor>();
auto color = format.property(FormatPrivate::P_Font_Color).value<XlsxColor>();
color.saveToXml(writer);
}

Expand Down
2 changes: 1 addition & 1 deletion QXlsx/source/xlsxutility.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ QVariant datetimeFromNumber(double num, bool is1904)
num = num - 1;
}

qint64 msecs = static_cast<qint64>(num * 1000 * 60 * 60 * 24.0 + 0.5);
auto msecs = static_cast<qint64>(std::lround(num * 1000 * 60 * 60 * 24.0));

if (is1904)
msecs += msecs1904;
Expand Down
Loading
Loading