Skip to content

Commit 7fcfee3

Browse files
committed
Enable -Wall and -Werror
1 parent 63b8951 commit 7fcfee3

File tree

10 files changed

+25
-38
lines changed

10 files changed

+25
-38
lines changed

CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,10 @@ target_link_libraries(${LIB_TARGET_NAME} PUBLIC ThirdParty::nonstd boost_variant
5555
target_include_directories(${LIB_TARGET_NAME}
5656
PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/include)
5757

58+
if(NOT MSVC)
59+
target_compile_options(${LIB_TARGET_NAME} PRIVATE -Wall -Werror)
60+
endif()
61+
5862
if (JINJA2CPP_BUILD_TESTS)
5963
enable_testing()
6064
add_subdirectory(thirdparty/gtest)

src/error_info.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ void RenderErrorInfo(std::basic_ostream<CharT>& os, const ErrorInfoTpl<CharT>& e
140140
if (extraParams.size() > 1)
141141
{
142142
os << UNIVERSAL_STR(". Expected: ");
143-
for (int i = 1; i < extraParams.size(); ++ i)
143+
for (std::size_t i = 1; i < extraParams.size(); ++ i)
144144
{
145145
if (i != 1)
146146
os << UNIVERSAL_STR(", ");

src/expression_evaluator.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -425,9 +425,9 @@ ParsedArguments ParseCallParamsImpl(const T& args, const CallParams& params, boo
425425
++ argIdx;
426426
}
427427

428-
int startPosArg = firstMandatoryIdx == -1 ? 0 : firstMandatoryIdx;
429-
int curPosArg = startPosArg;
430-
int eatenPosArgs = 0;
428+
std::size_t startPosArg = firstMandatoryIdx == -1 ? 0 : firstMandatoryIdx;
429+
std::size_t curPosArg = startPosArg;
430+
std::size_t eatenPosArgs = 0;
431431

432432
// Determine the range for positional arguments scanning
433433
bool isFirstTime = true;
@@ -445,7 +445,7 @@ ParsedArguments ParseCallParamsImpl(const T& args, const CallParams& params, boo
445445
int prevNotFound = argsInfo[startPosArg].prevNotFound;
446446
if (prevNotFound != -1)
447447
{
448-
startPosArg = prevNotFound;
448+
startPosArg = static_cast<std::size_t>(prevNotFound);
449449
}
450450
else if (curPosArg == args.size())
451451
{
@@ -456,20 +456,20 @@ ParsedArguments ParseCallParamsImpl(const T& args, const CallParams& params, boo
456456
int nextPosArg = argsInfo[curPosArg].nextNotFound;
457457
if (nextPosArg == -1)
458458
break;
459-
curPosArg = nextPosArg;
459+
curPosArg = static_cast<std::size_t>(nextPosArg);
460460
}
461461
}
462462

463463
// Map positional params to the desired arguments
464-
int curArg = startPosArg;
465-
for (int idx = 0; idx < eatenPosArgs && curArg != -1; ++ idx, curArg = argsInfo[curArg].nextNotFound)
464+
auto curArg = static_cast<int>(startPosArg);
465+
for (std::size_t idx = 0; idx < eatenPosArgs && curArg != -1; ++ idx, curArg = argsInfo[curArg].nextNotFound)
466466
{
467467
result.args[argsInfo[curArg].info->name] = params.posParams[idx];
468468
argsInfo[curArg].state = Positional;
469469
}
470470

471471
// Fill default arguments (if missing) and check for mandatory
472-
for (int idx = 0; idx < argsInfo.size(); ++ idx)
472+
for (std::size_t idx = 0; idx < argsInfo.size(); ++ idx)
473473
{
474474
auto& argInfo = argsInfo[idx];
475475
switch (argInfo.state)

src/filters.cpp

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -244,9 +244,9 @@ InternalValue DictSort::Filter(const InternalValue& baseVal, RenderContext& cont
244244

245245
std::vector<KeyValuePair> tempVector;
246246
tempVector.reserve(map->GetSize());
247-
for (int64_t idx = 0; idx < map->GetSize(); ++ idx)
247+
for (std::size_t idx = 0; idx < map->GetSize(); ++ idx)
248248
{
249-
auto val = map->GetValueByIndex(idx);
249+
auto val = map->GetValueByIndex(static_cast<std::int64_t>(idx));
250250
auto kvVal = Get<KeyValuePair>(val);
251251
tempVector.push_back(std::move(kvVal));
252252
}
@@ -569,17 +569,6 @@ InternalValue SequenceAccessor::Filter(const InternalValue& baseVal, RenderConte
569569
return ConvertToBool(cmpRes);
570570
};
571571

572-
auto equalComparator = [&attrName, &compType](auto& val1, auto& val2) {
573-
InternalValue cmpRes;
574-
575-
if (IsEmpty(attrName))
576-
cmpRes = Apply2<visitors::BinaryMathOperation>(val1, val2, BinaryExpression::LogicalEq, compType);
577-
else
578-
cmpRes = Apply2<visitors::BinaryMathOperation>(Subscript(val1, attrName), Subscript(val2, attrName), BinaryExpression::LogicalEq, compType);
579-
580-
return ConvertToBool(cmpRes);
581-
};
582-
583572
switch (m_mode)
584573
{
585574
case FirstItemMode:
@@ -618,7 +607,7 @@ InternalValue SequenceAccessor::Filter(const InternalValue& baseVal, RenderConte
618607
case ReverseMode:
619608
{
620609
InternalValueList resultList(list.GetSize());
621-
for (int n = 0; n < list.GetSize(); ++ n)
610+
for (std::size_t n = 0; n < list.GetSize(); ++ n)
622611
resultList[list.GetSize() - n - 1] = list.GetValueByIndex(n);
623612

624613
result = ListAdapter::CreateAdapter(std::move(resultList));

src/internal_value.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,7 @@ class ListAdapter::Iterator
294294
void increment()
295295
{
296296
++ m_current;
297-
m_currentVal = m_current == m_list->GetSize() ? InternalValue() : m_list->GetValueByIndex(m_current);
297+
m_currentVal = m_current == static_cast<int64_t>(m_list->GetSize()) ? InternalValue() : m_list->GetValueByIndex(m_current);
298298
}
299299

300300
bool equal(const Iterator& other) const
@@ -303,7 +303,7 @@ class ListAdapter::Iterator
303303
return other.m_list == nullptr ? true : other.equal(*this);
304304

305305
if (other.m_list == nullptr)
306-
return m_current == m_list->GetSize();
306+
return m_current == static_cast<int64_t>(m_list->GetSize());
307307

308308
return this->m_list == other.m_list && this->m_current == other.m_current;
309309
}

src/lexertk.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -851,14 +851,12 @@ namespace lexertk
851851

852852
++s_itr_;
853853

854-
bool escaped_found = false;
855854
bool escaped = false;
856855

857856
while (!is_end(s_itr_))
858857
{
859858
if (!escaped && ('\\' == *s_itr_))
860859
{
861-
escaped_found = true;
862860
escaped = true;
863861
++s_itr_;
864862

src/string_converter_filter.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,7 @@ StringConverter::StringConverter(FilterParams params, StringConverter::Mode mode
162162
case TruncateMode:
163163
ParseParams({{"length", false, static_cast<int64_t>(255)}, {"killwords", false, false}, {"end", false, std::string("...")}, {"leeway", false}}, params);
164164
break;
165+
default: break;
165166
}
166167
}
167168

@@ -245,12 +246,12 @@ InternalValue StringConverter::Filter(const InternalValue& baseVal, RenderContex
245246
auto killWords = ConvertToBool(this->GetArgumentValue("killwords", context));
246247
auto end = GetAsSameString(str, this->GetArgumentValue("end", context));
247248
auto leeway = ConvertToInt(this->GetArgumentValue("leeway", context), 5);
248-
if (str.size() <= length)
249+
if (static_cast<long long int>(str.size()) <= length)
249250
return InternalValue(str);
250251

251252
if (killWords)
252253
{
253-
if (str.size() > (length + leeway))
254+
if (static_cast<long long int>(str.size()) > (length + leeway))
254255
{
255256
str.erase(str.begin() + length, str.end());
256257
str += end;

src/template_parser.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -701,7 +701,7 @@ class TemplateParser : public LexerHelper
701701

702702
if (actualHeadLen == headLen)
703703
{
704-
for (int i = 0; i < col - actualHeadLen - spacePrefixLen; ++ i)
704+
for (std::size_t i = 0; i < col - actualHeadLen - spacePrefixLen; ++ i)
705705
os << toCharT(' ');
706706
}
707707
for (int i = 0; i < actualHeadLen; ++ i)

src/testers.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -210,14 +210,14 @@ bool ValueTester::Test(const InternalValue& baseVal, RenderContext& context)
210210
if (valKind == ValueKind::Integer)
211211
{
212212
auto intVal = ConvertToInt(val);
213-
result = testMode == (intVal & 1) == (EvenTest ? 0 : 1);
213+
result = (testMode == (intVal & 1)) == (EvenTest ? 0 : 1);
214214
}
215215
else if (valKind == ValueKind::Double)
216216
{
217217
auto dblVal = ConvertToDouble(val);
218218
int64_t intVal = dblVal;
219219
if (dblVal == intVal)
220-
result = testMode == (intVal & 1) == (EvenTest ? 0 : 1);
220+
result = (testMode == (intVal & 1)) == (EvenTest ? 0 : 1);
221221
}
222222
return result;
223223
};

src/value_visitors.h

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -795,13 +795,8 @@ struct StringJoiner : BaseVisitor<>
795795
}
796796
};
797797

798-
namespace
799-
{
800-
inline std::string GetSampleString();
801-
}
802-
803798
template<typename Fn>
804-
struct StringConverterImpl : public BaseVisitor<decltype(std::declval<Fn>()(GetSampleString()))>
799+
struct StringConverterImpl : public BaseVisitor<decltype(std::declval<Fn>()(std::declval<std::string>()))>
805800
{
806801
using R = decltype(std::declval<Fn>()(std::string()));
807802
using BaseVisitor<R>::operator ();

0 commit comments

Comments
 (0)