Skip to content

Commit 9b554ac

Browse files
author
Your Name
committed
Format
1 parent 81da87b commit 9b554ac

2 files changed

Lines changed: 31 additions & 29 deletions

File tree

lib/templatesimplifier.cpp

Lines changed: 27 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@
3333
#include <iostream>
3434
#include <map>
3535
#include <memory>
36-
#include <stack>
3736
#include <numeric>
37+
#include <stack>
3838
#include <type_traits>
3939
#include <unordered_map>
4040
#include <utility>
@@ -826,10 +826,10 @@ namespace {
826826
bool isSigned = false; // explicitly 'signed' (needed for "signed char")
827827
const Token* nameStart = nullptr; // ..or named base type [nameStart..nameEnd]
828828
const Token* nameEnd = nullptr;
829-
int pointer = 0; // pointer depth on top of the base type
830-
bool baseConst = false; // const qualifies the pointed to base type ("const char *")
831-
bool topConst = false; // const qualifies the outermost level ("const int", "char * const")
832-
bool fromArray = false; // pointer comes from array-to-pointer decay
829+
int pointer = 0; // pointer depth on top of the base type
830+
bool baseConst = false; // const qualifies the pointed to base type ("const char *")
831+
bool topConst = false; // const qualifies the outermost level ("const int", "char * const")
832+
bool fromArray = false; // pointer comes from array-to-pointer decay
833833

834834
bool isArithmetic() const {
835835
return valid && pointer == 0 && arith != ArithCat::None;
@@ -1118,7 +1118,8 @@ static ParsedType parseType(const Token* tok,
11181118
type.nameStart = start;
11191119
type.nameEnd = last;
11201120
if (templateParams && start == last) {
1121-
const auto it = std::find_if(templateParams->cbegin(), templateParams->cend(), [&](const Token* templateParam) {
1121+
const auto it =
1122+
std::find_if(templateParams->cbegin(), templateParams->cend(), [&](const Token* templateParam) {
11221123
return templateParam->str() == start->str();
11231124
});
11241125
if (it != templateParams->cend())
@@ -1213,7 +1214,7 @@ static DeducedToken arithToken(const ExprType& type)
12131214
{"short", false, true},
12141215
{"int", false, true},
12151216
{"long", false, true},
1216-
{"long", true, true}, // LongLong
1217+
{"long", true, true}, // LongLong
12171218
{"float", false, false},
12181219
{"double", false, false},
12191220
{"double", true, false}, // LongDouble
@@ -1643,7 +1644,7 @@ static ExprType parseOperandType(const DeductionContext& ctx, const Token*& tok,
16431644
type.baseConst = false;
16441645
}
16451646
type.fromArray = false;
1646-
} else { // "&"
1647+
} else { // "&"
16471648
if (type.pointer > 0 && type.topConst)
16481649
return ExprType(); // would need a "* const *" type
16491650
if (type.pointer == 0) {
@@ -1659,8 +1660,7 @@ static ExprType parseOperandType(const DeductionContext& ctx, const Token*& tok,
16591660
return type;
16601661
}
16611662

1662-
static bool isArithmeticOp(const std::string& s)
1663-
{
1663+
static bool isArithmeticOp(const std::string& s) {
16641664
return s == "+" || s == "-" || s == "*" || s == "/" || s == "%";
16651665
}
16661666

@@ -1669,13 +1669,11 @@ static bool isComparisonOp(const std::string& s)
16691669
return s == "==" || s == "!=" || s == "<=" || s == ">=" || s == "&&" || s == "||";
16701670
}
16711671

1672-
static bool isBitOp(const std::string& s)
1673-
{
1672+
static bool isBitOp(const std::string& s) {
16741673
return s == "&" || s == "|" || s == "^";
16751674
}
16761675

1677-
static bool isShiftOp(const std::string& s)
1678-
{
1676+
static bool isShiftOp(const std::string& s) {
16791677
return s == "<<" || s == ">>";
16801678
}
16811679

@@ -1684,14 +1682,15 @@ static bool isSupportedBinaryOp(const std::string& s)
16841682
return isArithmeticOp(s) || isComparisonOp(s) || isBitOp(s) || isShiftOp(s);
16851683
}
16861684

1687-
static bool isPointerType(const ExprType& type)
1688-
{
1685+
static bool isPointerType(const ExprType& type) {
16891686
return type.pointer > 0;
16901687
}
16911688

16921689
// fold |operands| with the usual arithmetic conversions
1693-
static ExprType convertArithmeticTypes(const Settings& settings, std::vector<ExprType>::const_iterator begin,
1694-
std::vector<ExprType>::const_iterator end, const ExprType& first)
1690+
static ExprType convertArithmeticTypes(const Settings& settings,
1691+
std::vector<ExprType>::const_iterator begin,
1692+
std::vector<ExprType>::const_iterator end,
1693+
const ExprType& first)
16951694
{
16961695
return std::accumulate(begin, end, first, [&](const ExprType& lhs, const ExprType& rhs) {
16971696
return usualArithmeticConversion(settings, lhs, rhs);
@@ -1773,8 +1772,8 @@ static ExprType evalExpressionType(const DeductionContext& ctx, const Token* sta
17731772
// the result is the promoted type of the sub expression left of the
17741773
// first shift operator
17751774
const std::size_t leftOfShift = firstShift - ops.cbegin();
1776-
const ExprType result = convertArithmeticTypes(*ctx.settings, operands.cbegin() + 1,
1777-
operands.cbegin() + 1 + leftOfShift, operands[0]);
1775+
const ExprType result =
1776+
convertArithmeticTypes(*ctx.settings, operands.cbegin() + 1, operands.cbegin() + 1 + leftOfShift, operands[0]);
17781777
return result.valid ? promoteType(*ctx.settings, result) : ExprType();
17791778
}
17801779

@@ -1795,7 +1794,7 @@ static std::vector<DeducedToken> deduceTemplateArgumentFromParam(const ParsedTyp
17951794
return {};
17961795
ExprType type = argType;
17971796
if (param.isReference && type.fromArray)
1798-
return {}; // T& does not decay
1797+
return {}; // T& does not decay
17991798
if (param.type.pointer > 0) {
18001799
if (param.isReference)
18011800
return {}; // T*& etc is not supported
@@ -1927,7 +1926,7 @@ static void deduceTemplateArgumentsAtFunctionCall(const DeductionContext& ctx,
19271926

19281927
if (param.form.templateParamIndex >= 0) {
19291928
if (!arg.type.valid)
1930-
continue; // maybe deducible from another argument
1929+
continue; // maybe deducible from another argument
19311930
std::vector<DeducedToken> tokens = deduceTemplateArgumentFromParam(param.form, arg.type);
19321931
if (tokens.empty()) {
19331932
failed = true; // the argument doesn't fit the parameter form
@@ -1981,9 +1980,12 @@ static void deduceTemplateArgumentsAtFunctionCall(const DeductionContext& ctx,
19811980
return match.exactMatches == maxExact;
19821981
}) != 1)
19831982
return;
1984-
winner = std::find_if(matches.cbegin(), matches.cend(), [&](const Candidate& match) {
1983+
winner = std::find_if(matches.cbegin(),
1984+
matches.cend(),
1985+
[&](const Candidate& match) {
19851986
return match.exactMatches == maxExact;
1986-
}) - matches.cbegin();
1987+
}) -
1988+
matches.cbegin();
19871989
}
19881990
}
19891991

@@ -2047,7 +2049,7 @@ static void recordClassMembers(DeductionSymbolTable& symbols, const Token* bodyS
20472049

20482050
namespace {
20492051
struct ClassHead {
2050-
Token* body = nullptr; // the "{" of the class body
2052+
Token* body = nullptr; // the "{" of the class body
20512053
const Token* nameTok = nullptr;
20522054
std::vector<std::string> baseClasses; // as written; template bases are left out
20532055
};

test/testsimplifytemplate.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -284,10 +284,10 @@ class TestSimplifyTemplate : public TestFixture {
284284
TEST_CASE(templateTypeDeduction3);
285285
TEST_CASE(templateTypeDeduction4); // #9983
286286
TEST_CASE(templateTypeDeduction5);
287-
TEST_CASE(templateTypeDeduction6); // deduction from variables
288-
TEST_CASE(templateTypeDeduction7); // parameter forms: T, T&, const T&, T*
289-
TEST_CASE(templateTypeDeduction8); // deduction from expressions
290-
TEST_CASE(templateTypeDeduction9); // multiple parameters, scopes, bailouts
287+
TEST_CASE(templateTypeDeduction6); // deduction from variables
288+
TEST_CASE(templateTypeDeduction7); // parameter forms: T, T&, const T&, T*
289+
TEST_CASE(templateTypeDeduction8); // deduction from expressions
290+
TEST_CASE(templateTypeDeduction9); // multiple parameters, scopes, bailouts
291291
TEST_CASE(templateTypeDeduction10); // parameter visibility: init list, const method
292292
TEST_CASE(templateTypeDeduction11); // unqualified lookup: enclosing scopes, shadowing
293293
TEST_CASE(templateTypeDeduction12); // base class member templates, out of class method bodies

0 commit comments

Comments
 (0)