aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorIvan Komissarov <abbapoh@gmail.com>2020-04-04 14:43:49 +0200
committerIvan Komissarov <ABBAPOH@gmail.com>2020-04-27 10:07:51 +0000
commitfbbddb1b67ab30b1c73a9ff1ae41ee5e344c0197 (patch)
tree78f1b6a5c82d2893f737f82699f27a7d1374e017 /src
parent37c992559fc79fd73828b653f80d0f2c3234568f (diff)
clang-tidy: Fix 'cppcoreguidelines-pro-type-member-init' warnings
Also, fix undefined behavior when setting and reading different field of a union (Lexer, Token) - according to the C++ Standard, it is not allowed to use a union to zero members of a struct. Treat these warnings as errors now. Change-Id: I0f6d071217ef55e2c75c51138fcff47048eca62f Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
Diffstat (limited to 'src')
-rw-r--r--src/lib/corelib/api/projectfileupdater.h2
-rw-r--r--src/lib/corelib/buildgraph/artifact.cpp17
-rw-r--r--src/lib/corelib/buildgraph/artifact.h1
-rw-r--r--src/lib/corelib/tools/fileinfo.cpp2
-rw-r--r--src/lib/corelib/tools/launcherpackets.h2
-rw-r--r--src/lib/corelib/tools/msvcinfo.cpp2
-rw-r--r--src/plugins/scanner/cpp/Lexer.cpp1
-rw-r--r--src/plugins/scanner/cpp/Lexer.h5
-rw-r--r--src/plugins/scanner/cpp/Token.cpp9
-rw-r--r--src/plugins/scanner/cpp/Token.h10
-rw-r--r--src/plugins/scanner/cpp/cppscanner.cpp8
-rw-r--r--src/plugins/scanner/qt/qtscanner.cpp2
12 files changed, 19 insertions, 42 deletions
diff --git a/src/lib/corelib/api/projectfileupdater.h b/src/lib/corelib/api/projectfileupdater.h
index 3459d788e..ded4e08a9 100644
--- a/src/lib/corelib/api/projectfileupdater.h
+++ b/src/lib/corelib/api/projectfileupdater.h
@@ -85,7 +85,7 @@ private:
const QString m_projectFile;
CodeLocation m_itemPosition;
- int m_lineOffset;
+ int m_lineOffset = 0;
};
diff --git a/src/lib/corelib/buildgraph/artifact.cpp b/src/lib/corelib/buildgraph/artifact.cpp
index e82919560..8d3a8bd3f 100644
--- a/src/lib/corelib/buildgraph/artifact.cpp
+++ b/src/lib/corelib/buildgraph/artifact.cpp
@@ -51,9 +51,13 @@
namespace qbs {
namespace Internal {
-Artifact::Artifact()
+Artifact::Artifact() :
+ artifactType(ArtifactType::Unknown),
+ inputsScanned(false),
+ timestampRetrieved(false),
+ alwaysUpdated(false),
+ oldDataPossiblyPresent(true)
{
- initialize();
}
Artifact::~Artifact()
@@ -120,15 +124,6 @@ RuleNode *Artifact::producer() const
return *ruleNodes.begin();
}
-void Artifact::initialize()
-{
- artifactType = Unknown;
- inputsScanned = false;
- timestampRetrieved = false;
- alwaysUpdated = true;
- oldDataPossiblyPresent = true;
-}
-
const TypeFilter<Artifact> Artifact::parentArtifacts() const
{
return TypeFilter<Artifact>(parents);
diff --git a/src/lib/corelib/buildgraph/artifact.h b/src/lib/corelib/buildgraph/artifact.h
index ee3acea59..2572a3b52 100644
--- a/src/lib/corelib/buildgraph/artifact.h
+++ b/src/lib/corelib/buildgraph/artifact.h
@@ -114,7 +114,6 @@ public:
bool alwaysUpdated : 1;
bool oldDataPossiblyPresent : 1;
- void initialize();
const TypeFilter<Artifact> parentArtifacts() const;
const TypeFilter<Artifact> childArtifacts() const;
void onChildDisconnected(BuildGraphNode *child) override;
diff --git a/src/lib/corelib/tools/fileinfo.cpp b/src/lib/corelib/tools/fileinfo.cpp
index 3bba06ada..8f6b285d4 100644
--- a/src/lib/corelib/tools/fileinfo.cpp
+++ b/src/lib/corelib/tools/fileinfo.cpp
@@ -450,7 +450,7 @@ static QByteArray storedLinkTarget(const QString &filePath)
const QByteArray nativeFilePath = QFile::encodeName(filePath);
ssize_t len;
while (true) {
- struct stat sb;
+ struct stat sb{};
if (lstat(nativeFilePath.constData(), &sb)) {
qWarning("storedLinkTarget: lstat for %s failed with error code %d",
nativeFilePath.constData(), errno);
diff --git a/src/lib/corelib/tools/launcherpackets.h b/src/lib/corelib/tools/launcherpackets.h
index 4306718fd..b3eac4320 100644
--- a/src/lib/corelib/tools/launcherpackets.h
+++ b/src/lib/corelib/tools/launcherpackets.h
@@ -145,7 +145,7 @@ class ProcessErrorPacket : public LauncherPacket
public:
ProcessErrorPacket(quintptr token);
- QProcess::ProcessError error;
+ QProcess::ProcessError error = QProcess::UnknownError;
QString errorString;
private:
diff --git a/src/lib/corelib/tools/msvcinfo.cpp b/src/lib/corelib/tools/msvcinfo.cpp
index 462f921a4..5097ca2e1 100644
--- a/src/lib/corelib/tools/msvcinfo.cpp
+++ b/src/lib/corelib/tools/msvcinfo.cpp
@@ -344,7 +344,7 @@ static std::vector<MSVCInstallInfo> retrieveInstancesFromVSWhere(
.append(formatVswhereOutput(stdOut, stdErr));
return result;
}
- QJsonParseError parseError;
+ QJsonParseError parseError{};
QJsonDocument jsonOutput = QJsonDocument::fromJson(vsWhere.readAllStandardOutput(),
&parseError);
if (parseError.error != QJsonParseError::NoError) {
diff --git a/src/plugins/scanner/cpp/Lexer.cpp b/src/plugins/scanner/cpp/Lexer.cpp
index 5bf5b2367..16556ac73 100644
--- a/src/plugins/scanner/cpp/Lexer.cpp
+++ b/src/plugins/scanner/cpp/Lexer.cpp
@@ -64,7 +64,6 @@ namespace CPlusPlus {
Lexer::Lexer(const char *firstChar, const char *lastChar)
: _state(State_Default),
- _flags(0),
_currentLine(1)
{
setSource(firstChar, lastChar);
diff --git a/src/plugins/scanner/cpp/Lexer.h b/src/plugins/scanner/cpp/Lexer.h
index 1cf829ebb..8f55f84e9 100644
--- a/src/plugins/scanner/cpp/Lexer.h
+++ b/src/plugins/scanner/cpp/Lexer.h
@@ -151,10 +151,7 @@ private:
const char *_tokenStart = nullptr;
unsigned char _yychar = 0;
int _state = 0;
- union {
- unsigned _flags;
- Flags f;
- };
+ Flags f{};
unsigned _currentLine = 0;
};
diff --git a/src/plugins/scanner/cpp/Token.cpp b/src/plugins/scanner/cpp/Token.cpp
index 603918f63..b488bf0d4 100644
--- a/src/plugins/scanner/cpp/Token.cpp
+++ b/src/plugins/scanner/cpp/Token.cpp
@@ -113,16 +113,9 @@ static const char *token_names[] = {
};
-Token::Token() :
- flags(0), offset(0), ptr(nullptr)
-{
-}
-
-Token::~Token() = default;
-
void Token::reset()
{
- flags = 0;
+ f = {};
offset = 0;
ptr = nullptr;
}
diff --git a/src/plugins/scanner/cpp/Token.h b/src/plugins/scanner/cpp/Token.h
index 846aa5a12..a042c1087 100644
--- a/src/plugins/scanner/cpp/Token.h
+++ b/src/plugins/scanner/cpp/Token.h
@@ -295,9 +295,6 @@ enum Kind {
class CPLUSPLUS_EXPORT Token
{
public:
- Token();
- ~Token();
-
inline bool is(unsigned k) const { return f.kind == k; }
inline bool isNot(unsigned k) const { return f.kind != k; }
#ifndef CPLUSPLUS_NO_PARSER
@@ -348,15 +345,12 @@ public:
unsigned pad : 3;
unsigned length : 16;
};
- union {
- unsigned flags;
- Flags f;
- };
+ Flags f{};
unsigned offset = 0;
union {
- void *ptr;
+ void *ptr = nullptr;
#ifndef CPLUSPLUS_NO_PARSER
const Literal *literal;
const NumericLiteral *number;
diff --git a/src/plugins/scanner/cpp/cppscanner.cpp b/src/plugins/scanner/cpp/cppscanner.cpp
index 191a0f8d2..0acb25172 100644
--- a/src/plugins/scanner/cpp/cppscanner.cpp
+++ b/src/plugins/scanner/cpp/cppscanner.cpp
@@ -65,9 +65,9 @@ using namespace CPlusPlus;
struct ScanResult
{
- char *fileName;
- int size;
- int flags;
+ char *fileName = nullptr;
+ int size = 0;
+ int flags = 0;
};
struct Opaq
@@ -226,7 +226,7 @@ static void *openScanner(const unsigned short *filePath, const char *fileTags, i
return nullptr;
}
- struct stat s;
+ struct stat s{};
int r = fstat(opaque->fd, &s);
if (r != 0)
return nullptr;
diff --git a/src/plugins/scanner/qt/qtscanner.cpp b/src/plugins/scanner/qt/qtscanner.cpp
index 22fdcb79d..22ef294d0 100644
--- a/src/plugins/scanner/qt/qtscanner.cpp
+++ b/src/plugins/scanner/qt/qtscanner.cpp
@@ -107,7 +107,7 @@ static void *openScannerQrc(const unsigned short *filePath, const char *fileTags
return nullptr;
}
- struct stat s;
+ struct stat s{};
int r = fstat(opaque->fd, &s);
if (r != 0)
return nullptr;