Skip to content

Commit d863b06

Browse files
author
Your Name
committed
Fix cppcheck premuim warnings
1 parent 979097b commit d863b06

1 file changed

Lines changed: 11 additions & 10 deletions

File tree

lib/templatesimplifier.cpp

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -812,7 +812,7 @@ namespace {
812812
std::string typeStr; // base type, e.g. "int" or "MyClass"
813813
std::vector<std::string> qualification; // enclosing scopes for record types, outermost first
814814
unsigned int constness = 0; // bit 0 = data const, bit 1 = first '*' const, ..
815-
int pointer = 0; // number of '*'
815+
unsigned int pointer = 0; // number of '*'
816816
bool isUnsigned = false;
817817
bool isLong = false;
818818

@@ -877,7 +877,7 @@ static DeducedType valueTypeToDeducedType(const ValueType* vt, const ParameterSh
877877
if (vt->smartPointer || vt->smartPointerType || vt->smartPointerTypeToken || vt->container || vt->containerTypeToken)
878878
return DeducedType();
879879

880-
int pointer = vt->pointer;
880+
unsigned int pointer = vt->pointer;
881881
unsigned int constness = vt->constness;
882882
if (shape.isPointer) {
883883
// "T *": the argument must be a pointer and T is the pointee type
@@ -1032,7 +1032,7 @@ namespace {
10321032
// Insert the tokens of a deduced type after tok (the tokens are inserted in reverse order)
10331033
static void insertDeducedType(Token* tok, const DeducedType& deduced)
10341034
{
1035-
for (int level = deduced.pointer; level >= 1; --level) {
1035+
for (unsigned int level = deduced.pointer; level >= 1; --level) {
10361036
if (deduced.constness & (1U << level))
10371037
tok->insertToken("const");
10381038
tok->insertToken("*");
@@ -1068,13 +1068,10 @@ struct TemplateSimplifier::DeductionCache {
10681068
std::vector<const Token*> declarationParams;
10691069
getFunctionArguments(candidate.nameToken(), declarationParams);
10701070

1071-
std::vector<bool> deducible(parsedCandidate.typeParameters.size(), false);
10721071
for (const Token* param : declarationParams) {
10731072
const ParameterShape shape = parseParameterShape(param, parsedCandidate.typeParameters);
10741073
if (!shape.typeTok)
10751074
return DeductionCandidate();
1076-
if (shape.templateParameterIndex >= 0)
1077-
deducible[shape.templateParameterIndex] = true;
10781075
parsedCandidate.parameterShapes.push_back(shape);
10791076
parsedCandidate.signature += (shape.isConst ? " const" : "");
10801077
// template parameters are compared by position - their names may differ
@@ -1086,10 +1083,14 @@ struct TemplateSimplifier::DeductionCache {
10861083
parsedCandidate.signature += (shape.isPointer ? " *" : shape.isReference ? " &" : "");
10871084
parsedCandidate.signature += ",";
10881085
}
1089-
if (!std::all_of(deducible.cbegin(), deducible.cend(), [](bool b) {
1090-
return b;
1091-
}))
1092-
return DeductionCandidate();
1086+
// every template parameter must be deducible from the function parameters
1087+
const int typeParameterCount = parsedCandidate.typeParameters.size();
1088+
for (int i = 0; i < typeParameterCount; ++i) {
1089+
if (std::none_of(parsedCandidate.parameterShapes.cbegin(), parsedCandidate.parameterShapes.cend(), [i](const ParameterShape& shape) {
1090+
return shape.templateParameterIndex == i;
1091+
}))
1092+
return DeductionCandidate();
1093+
}
10931094
return parsedCandidate;
10941095
}
10951096

0 commit comments

Comments
 (0)