Skip to content

Commit 266b2ae

Browse files
author
Your Name
committed
Make copy-constructible classes copyable
1 parent e7e54f7 commit 266b2ae

21 files changed

Lines changed: 320 additions & 89 deletions

.clang-tidy

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ Checks: >
1818
-objc-*,
1919
-openmp-*,
2020
-zircon-*,
21+
cppcoreguidelines-avoid-const-or-ref-data-members,
2122
cppcoreguidelines-pro-type-static-cast-downcast,
2223
cppcoreguidelines-rvalue-reference-param-not-moved,
2324
google-explicit-constructor,

Makefile

Lines changed: 13 additions & 9 deletions
Large diffs are not rendered by default.

clang-tidy.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,6 @@ Does not improve the readability.
138138
To be evaluated (need to remove exclusion).
139139

140140
`cppcoreguidelines-missing-std-forward`<br/>
141-
`cppcoreguidelines-avoid-const-or-ref-data-members`<br/>
142141
`cppcoreguidelines-macro-usage`<br/>
143142
`cppcoreguidelines-pro-type-member-init`<br/>
144143
`cppcoreguidelines-prefer-member-initializer`<br/>

cli/processexecutor.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -172,8 +172,8 @@ namespace {
172172
writeToPipeInternal(type, data.c_str(), len);
173173
}
174174

175-
const int mWpipe;
176-
const bool mDebug;
175+
int mWpipe;
176+
bool mDebug;
177177
};
178178
}
179179

lib/astutils.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
#include "infer.h"
2727
#include "library.h"
2828
#include "mathlib.h"
29+
#include "nonnullptr.h"
2930
#include "settings.h"
3031
#include "symboldatabase.h"
3132
#include "token.h"
@@ -3142,7 +3143,7 @@ namespace {
31423143
};
31433144

31443145
struct ExpressionChangedSkipDeadCode {
3145-
const Library& library;
3146+
NonNullPtr<const Library> library;
31463147
const std::function<std::vector<MathLib::bigint>(const Token* tok)>* evaluate;
31473148
ExpressionChangedSkipDeadCode(const Library& library,
31483149
const std::function<std::vector<MathLib::bigint>(const Token* tok)>& evaluate)

lib/checkother.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
#include "fwdanalysis.h"
2525
#include "library.h"
2626
#include "mathlib.h"
27+
#include "nonnullptr.h"
2728
#include "platform.h"
2829
#include "settings.h"
2930
#include "standards.h"
@@ -4513,7 +4514,7 @@ struct UnionMember {
45134514
: name(name)
45144515
, size(size) {}
45154516

4516-
const std::string &name;
4517+
NonNullPtr<const std::string> name;
45174518
size_t size;
45184519
};
45194520

@@ -4523,7 +4524,7 @@ struct Union {
45234524
, name(scope.className) {}
45244525

45254526
const Scope *scope;
4526-
const std::string &name;
4527+
NonNullPtr<const std::string> name;
45274528
std::vector<UnionMember> members;
45284529

45294530
const UnionMember *largestMember() const {
@@ -4632,7 +4633,7 @@ void CheckOtherImpl::unionZeroInitError(const Token *tok,
46324633
"Zero initializing union '$symbol' does not guarantee " +
46334634
"its complete storage to be zero initialized as its largest member " +
46344635
"is not declared as the first member. Consider making " +
4635-
largestMember.name + " the first member or favor memset().");
4636+
*largestMember.name + " the first member or favor memset().");
46364637
}
46374638

46384639
//-----------------------------------------------------------------------------

lib/checkstl.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#include "errortypes.h"
2323
#include "library.h"
2424
#include "mathlib.h"
25+
#include "nonnullptr.h"
2526
#include "pathanalysis.h"
2627
#include "settings.h"
2728
#include "standards.h"
@@ -2872,7 +2873,7 @@ namespace {
28722873
private:
28732874
const Token* mBodyTok;
28742875
const Token* mLoopVar{};
2875-
const Settings& mSettings;
2876+
NonNullPtr<const Settings> mSettings;
28762877
std::set<nonneg int> mVarsChanged;
28772878

28782879
public:
@@ -2895,7 +2896,7 @@ namespace {
28952896
int n = 1 + (astIsPointer(tok) ? 1 : 0);
28962897
for (int i = 0; i < n; i++) {
28972898
bool inconclusive = false;
2898-
if (isVariableChangedByFunctionCall(tok, i, mSettings.library, &inconclusive))
2899+
if (isVariableChangedByFunctionCall(tok, i, mSettings->library, &inconclusive))
28992900
return true;
29002901
if (inconclusive)
29012902
return true;

lib/clangimport.cpp

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020

2121
#include "errortypes.h"
2222
#include "mathlib.h"
23+
#include "nonnullptr.h"
2324
#include "standards.h"
2425
#include "symboldatabase.h"
2526
#include "token.h"
@@ -233,8 +234,8 @@ namespace clangimport {
233234
, mSymbolDatabase(symbolDatabase)
234235
{}
235236

236-
const Settings &mSettings;
237-
SymbolDatabase &mSymbolDatabase;
237+
NonNullPtr<const Settings> mSettings;
238+
NonNullPtr<SymbolDatabase> mSymbolDatabase;
238239

239240
int enumValue = 0;
240241

@@ -672,7 +673,7 @@ void clangimport::AstNode::addFullScopeNameTokens(TokenList &tokenList, const Sc
672673
const Scope *clangimport::AstNode::getNestedInScope(TokenList &tokenList)
673674
{
674675
if (!tokenList.back())
675-
return &mData->mSymbolDatabase.scopeList.front();
676+
return &mData->mSymbolDatabase->scopeList.front();
676677
if (tokenList.back()->str() == "}" && mData->mNotScope.find(tokenList.back()) == mData->mNotScope.end())
677678
return tokenList.back()->scope()->nestedIn;
678679
return tokenList.back()->scope();
@@ -1071,8 +1072,8 @@ Token *clangimport::AstNode::createTokens(TokenList &tokenList)
10711072
const_cast<Token *>(enumscope->bodyEnd)->deletePrevious();
10721073

10731074
// Create enum type
1074-
mData->mSymbolDatabase.typeList.emplace_back(enumtok, enumscope, enumtok->scope());
1075-
enumscope->definedType = &mData->mSymbolDatabase.typeList.back();
1075+
mData->mSymbolDatabase->typeList.emplace_back(enumtok, enumscope, enumtok->scope());
1076+
enumscope->definedType = &mData->mSymbolDatabase->typeList.back();
10761077
if (nametok)
10771078
const_cast<Scope *>(enumtok->scope())->definedTypesMap[nametok->str()] = enumscope->definedType;
10781079

@@ -1238,8 +1239,8 @@ Token *clangimport::AstNode::createTokens(TokenList &tokenList)
12381239
}
12391240

12401241
Scope *recordScope = createScope(tokenList, ScopeType::eStruct, children, classDef);
1241-
mData->mSymbolDatabase.typeList.emplace_back(classDef, recordScope, classDef->scope());
1242-
recordScope->definedType = &mData->mSymbolDatabase.typeList.back();
1242+
mData->mSymbolDatabase->typeList.emplace_back(classDef, recordScope, classDef->scope());
1243+
recordScope->definedType = &mData->mSymbolDatabase->typeList.back();
12431244
if (!recordName.empty()) {
12441245
recordScope->className = recordName;
12451246
const_cast<Scope *>(classDef->scope())->definedTypesMap[recordName] = recordScope->definedType;
@@ -1520,8 +1521,8 @@ void clangimport::AstNode::createTokensForCXXRecord(TokenList &tokenList)
15201521
const std::string addr = mExtTokens[0];
15211522
mData->scopeDecl(addr, scope);
15221523
scope->className = className;
1523-
mData->mSymbolDatabase.typeList.emplace_back(classToken, scope, classToken->scope());
1524-
scope->definedType = &mData->mSymbolDatabase.typeList.back();
1524+
mData->mSymbolDatabase->typeList.emplace_back(classToken, scope, classToken->scope());
1525+
scope->definedType = &mData->mSymbolDatabase->typeList.back();
15251526
const_cast<Scope *>(classToken->scope())->definedTypesMap[className] = scope->definedType;
15261527
}
15271528
addtoken(tokenList, ";");

lib/cppcheck.vcxproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,7 @@
159159
<ClInclude Include="library.h" />
160160
<ClInclude Include="matchcompiler.h" />
161161
<ClInclude Include="mathlib.h" />
162+
<ClInclude Include="nonnullptr.h" />
162163
<ClInclude Include="path.h" />
163164
<ClInclude Include="pathanalysis.h" />
164165
<ClInclude Include="pathmatch.h" />

lib/forwardanalyzer.cpp

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
#include "errorlogger.h"
2525
#include "errortypes.h"
2626
#include "mathlib.h"
27+
#include "nonnullptr.h"
2728
#include "settings.h"
2829
#include "symboldatabase.h"
2930
#include "token.h"
@@ -50,9 +51,9 @@ namespace {
5051
: analyzer(analyzer), tokenList(tokenList), errorLogger(errorLogger), settings(settings)
5152
{}
5253
ValuePtr<Analyzer> analyzer;
53-
const TokenList& tokenList;
54-
ErrorLogger& errorLogger;
55-
const Settings& settings;
54+
NonNullPtr<const TokenList> tokenList;
55+
NonNullPtr<ErrorLogger> errorLogger;
56+
NonNullPtr<const Settings> settings;
5657
Analyzer::Action actions;
5758
bool analyzeOnly{};
5859
bool analyzeTerminate{};
@@ -148,7 +149,7 @@ namespace {
148149
traverseRecursive(tok->astOperand2(), f, traverseUnknown);
149150
traverseRecursive(tok->astOperand1(), f, traverseUnknown);
150151
return Break(Analyzer::Terminate::Escape);
151-
} else if (Token::Match(tok, "%name% (") && isEscapeFunction(tok, settings.library)) {
152+
} else if (Token::Match(tok, "%name% (") && isEscapeFunction(tok, settings->library)) {
152153
// Traverse the parameters of the function before escaping
153154
traverseRecursive(tok->next()->astOperand2(), f, traverseUnknown);
154155
return Break(Analyzer::Terminate::Escape);
@@ -356,7 +357,7 @@ namespace {
356357

357358
bool isEscapeScope(const Token* endBlock, bool& unknown) const {
358359
const Token* ftok = nullptr;
359-
const bool r = isReturnScope(endBlock, settings.library, &ftok);
360+
const bool r = isReturnScope(endBlock, settings->library, &ftok);
360361
if (!r && ftok)
361362
unknown = true;
362363
return r;
@@ -690,9 +691,9 @@ namespace {
690691
}
691692
} else if (tok->isControlFlowKeyword() && Token::Match(tok, "if|while|for (") &&
692693
Token::simpleMatch(tok->linkAt(1), ") {")) {
693-
if ((settings.vfOptions.maxForwardBranches > 0) && (++branchCount > settings.vfOptions.maxForwardBranches)) {
694+
if ((settings->vfOptions.maxForwardBranches > 0) && (++branchCount > settings->vfOptions.maxForwardBranches)) {
694695
// TODO: should be logged on function-level instead of file-level
695-
if (settings.severity.isEnabled(Severity::information)) {
696+
if (settings->severity.isEnabled(Severity::information)) {
696697
reportError(Severity::information, "normalCheckLevelMaxBranches", "Limiting analysis of branches. Use --check-level=exhaustive to analyze all branches.");
697698
}
698699
return Break(Analyzer::Terminate::Bail);
@@ -802,8 +803,8 @@ namespace {
802803
// Carry the then-fork forward, unless a limit is hit - then only the linear main
803804
// path continues (no bail). forkDepth bounds nesting, forkBudget total. <0 = off.
804805
assert(forkBudget != nullptr);
805-
const int forkDepthLimit = settings.vfOptions.maxForwardConditionForkDepth;
806-
const int forkBudgetLimit = settings.vfOptions.maxForwardConditionForks;
806+
const int forkDepthLimit = settings->vfOptions.maxForwardConditionForkDepth;
807+
const int forkBudgetLimit = settings->vfOptions.maxForwardConditionForks;
807808
const bool depthOk = forkDepthLimit < 0 || forkDepth < forkDepthLimit;
808809
const bool budgetOk = forkBudgetLimit < 0 || *forkBudget < forkBudgetLimit;
809810
if (pThen != Progress::Break && !thenBranch.isEscape() && depthOk && budgetOk) {
@@ -890,10 +891,10 @@ namespace {
890891
return Progress::Continue;
891892
}
892893

893-
void reportError(Severity severity, const std::string& id, const std::string& msg) {
894-
ErrorMessage::FileLocation loc(tokenList.getSourceFilePath(), 0, 0);
895-
const ErrorMessage errmsg({std::move(loc)}, tokenList.getSourceFilePath(), severity, msg, id, Certainty::normal);
896-
errorLogger.reportErr(errmsg);
894+
void reportError(Severity severity, const std::string& id, const std::string& msg) const {
895+
ErrorMessage::FileLocation loc(tokenList->getSourceFilePath(), 0, 0);
896+
const ErrorMessage errmsg({std::move(loc)}, tokenList->getSourceFilePath(), severity, msg, id, Certainty::normal);
897+
errorLogger->reportErr(errmsg);
897898
}
898899

899900
static bool isFunctionCall(const Token* tok)

0 commit comments

Comments
 (0)