Skip to content

Commit d4f02b5

Browse files
committed
Address sign promotion warnings, add todo test
1 parent 645377e commit d4f02b5

11 files changed

Lines changed: 51 additions & 28 deletions

File tree

.decent_ci-Linux.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,4 +38,5 @@ compilers:
3838
- name: custom_check
3939
commands:
4040
- ./contrib/check_for_tabs.rb
41+
- ./contrib/check_for_todos.rb
4142

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ else()
178178
add_definitions(-Wall -Wextra -Wconversion -Wshadow -Wnon-virtual-dtor -Wold-style-cast -Wcast-align -Wcast-qual -Wunused -Woverloaded-virtual -pedantic ${CPP11_FLAG})
179179

180180
if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
181-
add_definitions(-Weverything -Wno-c++98-compat-pedantic -Wno-c++98-compat -Wno-documentation -Wno-switch-enum -Wno-weak-vtables -Wno-sign-conversion -Wno-missing-prototypes -Wno-padded -Wno-missing-noreturn -Wno-exit-time-destructors -Wno-documentation-unknown-command)
181+
add_definitions(-Weverything -Wno-c++98-compat-pedantic -Wno-c++98-compat -Wno-documentation -Wno-switch-enum -Wno-weak-vtables -Wno-missing-prototypes -Wno-padded -Wno-missing-noreturn -Wno-exit-time-destructors -Wno-documentation-unknown-command)
182182
else()
183183
add_definitions(-Wnoexcept)
184184
endif()

contrib/check_for_todos.rb

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#!/usr/bin/env ruby
2+
3+
require 'json'
4+
5+
`grep -rPIHni 'todo' src/* include/* samples/*`.lines { |line|
6+
if /(?<filename>.+(hpp|cpp|chai)):(?<linenumber>[0-9]+):(?<restofline>.+)/ =~ line
7+
puts(JSON.dump({:line => linenumber, :filename => filename, :tool => "todo_checker", :message => "todo: #{restofline.strip}", :messagetype => "info"}))
8+
end
9+
}
10+
11+

include/chaiscript/chaiscript_defines.hpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,12 @@ namespace chaiscript {
113113
#endif
114114
}
115115

116+
template<typename Iter, typename Distance>
117+
Iter advance_copy(Iter iter, Distance distance) {
118+
std::advance(iter, static_cast<typename std::iterator_traits<Iter>::difference_type>(distance));
119+
return iter;
120+
}
121+
116122
}
117123
#endif
118124

include/chaiscript/dispatchkit/bootstrap_stl.hpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -248,13 +248,17 @@ namespace chaiscript
248248
m->add(
249249
fun(
250250
[](ContainerType &c, int index) -> typename ContainerType::reference {
251-
return c.at(index);
251+
/// \todo we are prefering to keep the key as 'int' to avoid runtime conversions
252+
/// during dispatch. reevaluate
253+
return c.at(static_cast<typename ContainerType::size_type>(index));
252254
}), "[]");
253255

254256
m->add(
255257
fun(
256258
[](const ContainerType &c, int index) -> typename ContainerType::const_reference {
257-
return c.at(index);
259+
/// \todo we are prefering to keep the key as 'int' to avoid runtime conversions
260+
/// during dispatch. reevaluate
261+
return c.at(static_cast<typename ContainerType::size_type>(index));
258262
}), "[]");
259263

260264
return m;

include/chaiscript/dispatchkit/dispatchkit.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1445,7 +1445,7 @@ namespace chaiscript
14451445
static typename Container::const_iterator find_keyed_value(const Container &t_c, const Key &t_key, const size_t t_hint)
14461446
{
14471447
if (t_c.size() > t_hint && t_c[t_hint].first == t_key) {
1448-
return t_c.begin() + t_hint;
1448+
return advance_copy(t_c.begin(), t_hint);
14491449
} else {
14501450
return find_keyed_value(t_c, t_key);
14511451
}

include/chaiscript/dispatchkit/type_info.hpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,11 @@ namespace chaiscript
3232
CHAISCRIPT_CONSTEXPR Type_Info(bool t_is_const, bool t_is_reference, bool t_is_pointer, bool t_is_void,
3333
bool t_is_arithmetic, const std::type_info *t_ti, const std::type_info *t_bare_ti)
3434
: m_type_info(t_ti), m_bare_type_info(t_bare_ti),
35-
m_flags((t_is_const << is_const_flag)
36-
+ (t_is_reference << is_reference_flag)
37-
+ (t_is_pointer << is_pointer_flag)
38-
+ (t_is_void << is_void_flag)
39-
+ (t_is_arithmetic << is_arithmetic_flag))
35+
m_flags((static_cast<unsigned int>(t_is_const) << is_const_flag)
36+
+ (static_cast<unsigned int>(t_is_reference) << is_reference_flag)
37+
+ (static_cast<unsigned int>(t_is_pointer) << is_pointer_flag)
38+
+ (static_cast<unsigned int>(t_is_void) << is_void_flag)
39+
+ (static_cast<unsigned int>(t_is_arithmetic) << is_arithmetic_flag))
4040
{
4141
}
4242

include/chaiscript/language/chaiscript_engine.hpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -505,10 +505,10 @@ namespace chaiscript
505505

506506
// Let's see if this is a link that we should expand
507507
std::vector<char> buf(2048);
508-
const size_t pathlen = readlink(dllpath.c_str(), &buf.front(), buf.size());
509-
if (pathlen > 0 && pathlen < buf.size())
508+
const auto pathlen = readlink(dllpath.c_str(), &buf.front(), buf.size());
509+
if (pathlen > 0 && static_cast<size_t>(pathlen) < buf.size())
510510
{
511-
dllpath = std::string(&buf.front(), pathlen);
511+
dllpath = std::string(&buf.front(), static_cast<size_t>(pathlen));
512512
}
513513

514514
m_module_paths.insert(m_module_paths.begin(), dllpath+"/");

include/chaiscript/language/chaiscript_parser.hpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ namespace chaiscript
147147
}
148148

149149
size_t remaining() const {
150-
return std::distance(m_pos, m_end);
150+
return static_cast<size_t>(std::distance(m_pos, m_end));
151151
}
152152

153153
char operator*() const {
@@ -2213,8 +2213,8 @@ namespace chaiscript
22132213

22142214
switch (m_operators[t_precedence]) {
22152215
case(AST_Node_Type::Ternary_Cond) :
2216-
m_match_stack.erase(m_match_stack.begin() + m_match_stack.size() - 2,
2217-
m_match_stack.begin() + m_match_stack.size() - 1);
2216+
m_match_stack.erase(advance_copy(m_match_stack.begin(), m_match_stack.size() - 2),
2217+
advance_copy(m_match_stack.begin(), m_match_stack.size() - 1));
22182218
if (Symbol(":")) {
22192219
if (!Operator(t_precedence+1)) {
22202220
throw exception::eval_error("Incomplete "
@@ -2239,7 +2239,8 @@ namespace chaiscript
22392239
case(AST_Node_Type::Bitwise_Or) :
22402240
case(AST_Node_Type::Comparison) :
22412241
assert(m_match_stack.size() > 1);
2242-
m_match_stack.erase(m_match_stack.begin() + m_match_stack.size() - 2, m_match_stack.begin() + m_match_stack.size() - 1);
2242+
m_match_stack.erase(advance_copy(m_match_stack.begin(), m_match_stack.size() - 2),
2243+
advance_copy(m_match_stack.begin(), m_match_stack.size() - 1));
22432244
build_match<eval::Binary_Operator_AST_Node>(prev_stack_top, oper->text);
22442245
break;
22452246

src/main.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -88,24 +88,24 @@ std::vector<std::string> default_search_paths()
8888
std::vector<char> buf(2048);
8989
ssize_t size = -1;
9090

91-
if ((size = readlink("/proc/self/exe", &buf.front(), buf.size())) != -1)
91+
if ((size = readlink("/proc/self/exe", &buf.front(), buf.size())) >= 0)
9292
{
93-
exepath = std::string(&buf.front(), size);
93+
exepath = std::string(&buf.front(), static_cast<size_t>(size));
9494
}
9595

9696
if (exepath.empty())
9797
{
98-
if ((size = readlink("/proc/curproc/file", &buf.front(), buf.size())) != -1)
98+
if ((size = readlink("/proc/curproc/file", &buf.front(), buf.size())) >= 0)
9999
{
100-
exepath = std::string(&buf.front(), size);
100+
exepath = std::string(&buf.front(), static_cast<size_t>(size));
101101
}
102102
}
103103

104104
if (exepath.empty())
105105
{
106-
if ((size = readlink("/proc/self/path/a.out", &buf.front(), buf.size())) != -1)
106+
if ((size = readlink("/proc/self/path/a.out", &buf.front(), buf.size())) >= 0)
107107
{
108-
exepath = std::string(&buf.front(), size);
108+
exepath = std::string(&buf.front(), static_cast<size_t>(size));
109109
}
110110
}
111111

0 commit comments

Comments
 (0)