[clang-tidy] Replace C style casts with C++ ones

Found with google-readability-casting

Signed-off-by: Rosen Penev <rosenp@gmail.com>
This commit is contained in:
Rosen Penev 2019-09-27 20:42:34 -07:00 committed by Paul Beckingham
parent 55d103c491
commit 13e1bf7204
14 changed files with 86 additions and 86 deletions

View file

@ -1035,7 +1035,7 @@ void Context::getLimits (int& rows, int& lines)
} }
else else
{ {
rows = (int) strtol (limit.c_str (), nullptr, 10); rows = static_cast<int>(strtol (limit.c_str (), nullptr, 10));
lines = 0; lines = 0;
} }
} }

View file

@ -387,7 +387,7 @@ bool getDOM (const std::string& name, const Task& task, Variant& value)
{ {
// annotation_1234567890 // annotation_1234567890
// 0 ^11 // 0 ^11
value = Variant ((time_t) strtol (i.first.substr (11).c_str (), NULL, 10), Variant::type_date); value = Variant (static_cast<time_t>(strtol (i.first.substr (11).c_str (), NULL, 10)), Variant::type_date);
return true; return true;
} }
else if (elements[2] == "description") else if (elements[2] == "description")
@ -646,7 +646,7 @@ std::string DOM::Node::dumpNode (
out << "\033[31m" << node->_name << "\033[0m"; out << "\033[31m" << node->_name << "\033[0m";
if (node->_provider) if (node->_provider)
out << " 0x" << std::hex << (long long) (void*) node->_provider; out << " 0x" << std::hex << (long long) reinterpret_cast<void*>(node->_provider);
out << '\n'; out << '\n';

View file

@ -237,7 +237,7 @@ void Eval::evaluatePostfixStack (
Variant result = ! right; Variant result = ! right;
values.push_back (result); values.push_back (result);
if (_debug) if (_debug)
Context::getContext ().debug (format ("Eval {1} ↓'{2}' → ↑'{3}'", token.first, (std::string) right, (std::string) result)); Context::getContext ().debug (format ("Eval {1} ↓'{2}' → ↑'{3}'", token.first, std::string(right), std::string(result)));
} }
else if (token.second == Lexer::Type::op && else if (token.second == Lexer::Type::op &&
token.first == "_neg_") token.first == "_neg_")
@ -253,7 +253,7 @@ void Eval::evaluatePostfixStack (
values.push_back (result); values.push_back (result);
if (_debug) if (_debug)
Context::getContext ().debug (format ("Eval {1} ↓'{2}' → ↑'{3}'", token.first, (std::string) right, (std::string) result)); Context::getContext ().debug (format ("Eval {1} ↓'{2}' → ↑'{3}'", token.first, std::string(right), std::string(result)));
} }
else if (token.second == Lexer::Type::op && else if (token.second == Lexer::Type::op &&
token.first == "_pos_") token.first == "_pos_")
@ -306,7 +306,7 @@ void Eval::evaluatePostfixStack (
values.push_back (result); values.push_back (result);
if (_debug) if (_debug)
Context::getContext ().debug (format ("Eval ↓'{1}' {2} ↓'{3}' → ↑'{4}'", (std::string) left, token.first, (std::string) right, (std::string) result)); Context::getContext ().debug (format ("Eval ↓'{1}' {2} ↓'{3}' → ↑'{4}'", std::string(left), token.first, std::string(right), std::string(result)));
} }
// Literals and identifiers. // Literals and identifiers.
@ -320,13 +320,13 @@ void Eval::evaluatePostfixStack (
{ {
v.cast (Variant::type_integer); v.cast (Variant::type_integer);
if (_debug) if (_debug)
Context::getContext ().debug (format ("Eval literal number ↑'{1}'", (std::string) v)); Context::getContext ().debug (format ("Eval literal number ↑'{1}'", std::string(v)));
} }
else else
{ {
v.cast (Variant::type_real); v.cast (Variant::type_real);
if (_debug) if (_debug)
Context::getContext ().debug (format ("Eval literal decimal ↑'{1}'", (std::string) v)); Context::getContext ().debug (format ("Eval literal decimal ↑'{1}'", std::string(v)));
} }
break; break;
@ -343,7 +343,7 @@ void Eval::evaluatePostfixStack (
if (_source (token.first, v)) if (_source (token.first, v))
{ {
if (_debug) if (_debug)
Context::getContext ().debug (format ("Eval identifier source '{1}' → ↑'{2}'", token.first, (std::string) v)); Context::getContext ().debug (format ("Eval identifier source '{1}' → ↑'{2}'", token.first, std::string(v)));
found = true; found = true;
break; break;
} }
@ -362,20 +362,20 @@ void Eval::evaluatePostfixStack (
case Lexer::Type::date: case Lexer::Type::date:
v.cast (Variant::type_date); v.cast (Variant::type_date);
if (_debug) if (_debug)
Context::getContext ().debug (format ("Eval literal date ↑'{1}'", (std::string) v)); Context::getContext ().debug (format ("Eval literal date ↑'{1}'", std::string(v)));
break; break;
case Lexer::Type::duration: case Lexer::Type::duration:
v.cast (Variant::type_duration); v.cast (Variant::type_duration);
if (_debug) if (_debug)
Context::getContext ().debug (format ("Eval literal duration ↑'{1}'", (std::string) v)); Context::getContext ().debug (format ("Eval literal duration ↑'{1}'", std::string(v)));
break; break;
// Nothing to do. // Nothing to do.
case Lexer::Type::string: case Lexer::Type::string:
default: default:
if (_debug) if (_debug)
Context::getContext ().debug (format ("Eval literal string ↑'{1}'", (std::string) v)); Context::getContext ().debug (format ("Eval literal string ↑'{1}'", std::string(v)));
break; break;
} }

View file

@ -57,7 +57,7 @@ bool domSource (const std::string& identifier, Variant& value)
void Filter::subset (const std::vector <Task>& input, std::vector <Task>& output) void Filter::subset (const std::vector <Task>& input, std::vector <Task>& output)
{ {
Timer timer; Timer timer;
_startCount = (int) input.size (); _startCount = static_cast<int>(input.size ());
Context::getContext ().cli2.prepareFilter (); Context::getContext ().cli2.prepareFilter ();
@ -92,7 +92,7 @@ void Filter::subset (const std::vector <Task>& input, std::vector <Task>& output
else else
output = input; output = input;
_endCount = (int) output.size (); _endCount = static_cast<int>(output.size ());
Context::getContext ().debug (format ("Filtered {1} tasks --> {2} tasks [list subset]", _startCount, _endCount)); Context::getContext ().debug (format ("Filtered {1} tasks --> {2} tasks [list subset]", _startCount, _endCount));
Context::getContext ().time_filter_us += timer.total_us (); Context::getContext ().time_filter_us += timer.total_us ();
} }
@ -117,7 +117,7 @@ void Filter::subset (std::vector <Task>& output)
Timer timer_pending; Timer timer_pending;
auto pending = Context::getContext ().tdb2.pending.get_tasks (); auto pending = Context::getContext ().tdb2.pending.get_tasks ();
Context::getContext ().time_filter_us -= timer_pending.total_us (); Context::getContext ().time_filter_us -= timer_pending.total_us ();
_startCount = (int) pending.size (); _startCount = static_cast<int>(pending.size ());
Eval eval; Eval eval;
eval.addSource (domSource); eval.addSource (domSource);
@ -145,7 +145,7 @@ void Filter::subset (std::vector <Task>& output)
Timer timer_completed; Timer timer_completed;
auto completed = Context::getContext ().tdb2.completed.get_tasks (); auto completed = Context::getContext ().tdb2.completed.get_tasks ();
Context::getContext ().time_filter_us -= timer_completed.total_us (); Context::getContext ().time_filter_us -= timer_completed.total_us ();
_startCount += (int) completed.size (); _startCount += static_cast<int>(completed.size ());
for (auto& task : completed) for (auto& task : completed)
{ {
@ -174,7 +174,7 @@ void Filter::subset (std::vector <Task>& output)
Context::getContext ().time_filter_us -= pending_completed.total_us (); Context::getContext ().time_filter_us -= pending_completed.total_us ();
} }
_endCount = (int) output.size (); _endCount = static_cast<int>(output.size ());
Context::getContext ().debug (format ("Filtered {1} tasks --> {2} tasks [{3}]", _startCount, _endCount, (shortcut ? "pending only" : "all tasks"))); Context::getContext ().debug (format ("Filtered {1} tasks --> {2} tasks [{3}]", _startCount, _endCount, (shortcut ? "pending only" : "all tasks")));
Context::getContext ().time_filter_us += timer.total_us (); Context::getContext ().time_filter_us += timer.total_us ();
} }
@ -209,8 +209,8 @@ bool Filter::pendingOnly () const
int countPending = 0; int countPending = 0;
int countWaiting = 0; int countWaiting = 0;
int countRecurring = 0; int countRecurring = 0;
int countId = (int) Context::getContext ().cli2._id_ranges.size (); int countId = static_cast<int>(Context::getContext ().cli2._id_ranges.size ());
int countUUID = (int) Context::getContext ().cli2._uuid_list.size (); int countUUID = static_cast<int>(Context::getContext ().cli2._uuid_list.size ());
int countOr = 0; int countOr = 0;
int countXor = 0; int countXor = 0;
int countNot = 0; int countNot = 0;

View file

@ -471,7 +471,7 @@ void Hooks::assertNTasks (
{ {
if (input.size () != n) if (input.size () != n)
{ {
Context::getContext ().error (format (STRING_HOOK_ERROR_BAD_NUM, n, (int) input.size (), Path (script).name ())); Context::getContext ().error (format (STRING_HOOK_ERROR_BAD_NUM, n, static_cast<int>(input.size ()), Path (script).name ()));
throw 0; throw 0;
} }
} }

View file

@ -355,7 +355,7 @@ std::string Lexer::commify (const std::string& data)
int end = -1; int end = -1;
int i; int i;
for (int i = 0; i < (int) data.length (); ++i) for (int i = 0; i < static_cast<int>(data.length ()); ++i)
{ {
if (unicodeLatinDigit (data[i])) if (unicodeLatinDigit (data[i]))
end = i; end = i;
@ -369,7 +369,7 @@ std::string Lexer::commify (const std::string& data)
{ {
// In reverse order, transfer all digits up to, and including the decimal // In reverse order, transfer all digits up to, and including the decimal
// point. // point.
for (i = (int) data.length () - 1; i >= decimalPoint; --i) for (i = static_cast<int>(data.length ()) - 1; i >= decimalPoint; --i)
result += data[i]; result += data[i];
int consecutiveDigits = 0; int consecutiveDigits = 0;
@ -393,7 +393,7 @@ std::string Lexer::commify (const std::string& data)
{ {
// In reverse order, transfer all digits up to, but not including the last // In reverse order, transfer all digits up to, but not including the last
// digit. // digit.
for (i = (int) data.length () - 1; i > end; --i) for (i = static_cast<int>(data.length ()) - 1; i > end; --i)
result += data[i]; result += data[i];
int consecutiveDigits = 0; int consecutiveDigits = 0;
@ -416,7 +416,7 @@ std::string Lexer::commify (const std::string& data)
// reverse result into data. // reverse result into data.
std::string done; std::string done;
for (int i = (int) result.length () - 1; i >= 0; --i) for (int i = static_cast<int>(result.length ()) - 1; i >= 0; --i)
done += result[i]; done += result[i];
return done; return done;
@ -1463,20 +1463,20 @@ bool Lexer::readWord (
switch (c) switch (c)
{ {
case '"': word += (char) 0x22; ++cursor; break; case '"': word += static_cast<char>(0x22); ++cursor; break;
case '\'': word += (char) 0x27; ++cursor; break; case '\'': word += static_cast<char>(0x27); ++cursor; break;
case '\\': word += (char) 0x5C; ++cursor; break; case '\\': word += static_cast<char>(0x5C); ++cursor; break;
case 'b': word += (char) 0x08; ++cursor; break; case 'b': word += static_cast<char>(0x08); ++cursor; break;
case 'f': word += (char) 0x0C; ++cursor; break; case 'f': word += static_cast<char>(0x0C); ++cursor; break;
case 'n': word += (char) 0x0A; ++cursor; break; case 'n': word += static_cast<char>(0x0A); ++cursor; break;
case 'r': word += (char) 0x0D; ++cursor; break; case 'r': word += static_cast<char>(0x0D); ++cursor; break;
case 't': word += (char) 0x09; ++cursor; break; case 't': word += static_cast<char>(0x09); ++cursor; break;
case 'v': word += (char) 0x0B; ++cursor; break; case 'v': word += static_cast<char>(0x0B); ++cursor; break;
// This pass-through default case means that anything can be escaped // This pass-through default case means that anything can be escaped
// harmlessly. In particular 'quote' is included, if it not one of the // harmlessly. In particular 'quote' is included, if it not one of the
// above characters. // above characters.
default: word += (char) c; ++cursor; break; default: word += static_cast<char>(c); ++cursor; break;
} }
} }
@ -1547,20 +1547,20 @@ bool Lexer::readWord (
switch (c) switch (c)
{ {
case '"': word += (char) 0x22; ++cursor; break; case '"': word += static_cast<char>(0x22); ++cursor; break;
case '\'': word += (char) 0x27; ++cursor; break; case '\'': word += static_cast<char>(0x27); ++cursor; break;
case '\\': word += (char) 0x5C; ++cursor; break; case '\\': word += static_cast<char>(0x5C); ++cursor; break;
case 'b': word += (char) 0x08; ++cursor; break; case 'b': word += static_cast<char>(0x08); ++cursor; break;
case 'f': word += (char) 0x0C; ++cursor; break; case 'f': word += static_cast<char>(0x0C); ++cursor; break;
case 'n': word += (char) 0x0A; ++cursor; break; case 'n': word += static_cast<char>(0x0A); ++cursor; break;
case 'r': word += (char) 0x0D; ++cursor; break; case 'r': word += static_cast<char>(0x0D); ++cursor; break;
case 't': word += (char) 0x09; ++cursor; break; case 't': word += static_cast<char>(0x09); ++cursor; break;
case 'v': word += (char) 0x0B; ++cursor; break; case 'v': word += static_cast<char>(0x0B); ++cursor; break;
// This pass-through default case means that anything can be escaped // This pass-through default case means that anything can be escaped
// harmlessly. In particular 'quote' is included, if it not one of the // harmlessly. In particular 'quote' is included, if it not one of the
// above characters. // above characters.
default: word += (char) c; ++cursor; break; default: word += static_cast<char>(c); ++cursor; break;
} }
} }

View file

@ -577,12 +577,12 @@ std::string TF2::dump ()
// Hygiene. // Hygiene.
std::string hygiene = _dirty ? red.colorize ("O") : green.colorize ("-"); std::string hygiene = _dirty ? red.colorize ("O") : green.colorize ("-");
std::string tasks = green.colorize (rightJustifyZero ((int) _tasks.size (), 4)); std::string tasks = green.colorize (rightJustifyZero (static_cast<int>(_tasks.size ()), 4));
std::string tasks_added = red.colorize (rightJustifyZero ((int) _added_tasks.size (), 3)); std::string tasks_added = red.colorize (rightJustifyZero (static_cast<int>(_added_tasks.size ()), 3));
std::string tasks_modified = yellow.colorize (rightJustifyZero ((int) _modified_tasks.size (), 3)); std::string tasks_modified = yellow.colorize (rightJustifyZero (static_cast<int>(_modified_tasks.size ()), 3));
std::string tasks_purged = red.colorize (rightJustifyZero ((int) _purged_tasks.size (), 3)); std::string tasks_purged = red.colorize (rightJustifyZero (static_cast<int>(_purged_tasks.size ()), 3));
std::string lines = green.colorize (rightJustifyZero ((int) _lines.size (), 4)); std::string lines = green.colorize (rightJustifyZero (static_cast<int>(_lines.size ()), 4));
std::string lines_added = red.colorize (rightJustifyZero ((int) _added_lines.size (), 3)); std::string lines_added = red.colorize (rightJustifyZero (static_cast<int>(_added_lines.size ()), 3));
char buffer[256]; // Composed string is actually 246 bytes. Yikes. char buffer[256]; // Composed string is actually 246 bytes. Yikes.
snprintf (buffer, 256, "%14s %s %s T%s+%s~%s-%s L%s+%s", snprintf (buffer, 256, "%14s %s %s T%s+%s~%s-%s L%s+%s",

View file

@ -301,7 +301,7 @@ void TLSClient::connect (const std::string& host, const std::string& port)
gnutls_datum_t out; gnutls_datum_t out;
gnutls_certificate_verification_status_print (status, type, &out, 0); // 3.1.4 gnutls_certificate_verification_status_print (status, type, &out, 0); // 3.1.4
std::string error {(const char*) out.data}; std::string error {reinterpret_cast<const char*>(out.data)};
gnutls_free (out.data); // All gnutls_free (out.data); // All
throw format ("Handshake failed. {1}", error); // All throw format ("Handshake failed. {1}", error); // All
@ -484,8 +484,8 @@ void TLSClient::send (const std::string& data)
if (status == -1) if (status == -1)
break; break;
total += (unsigned int) status; total += static_cast<unsigned int>(status);
remaining -= (unsigned int) status; remaining -= static_cast<unsigned int>(status);
} }
if (_debug) if (_debug)
@ -564,7 +564,7 @@ void TLSClient::recv (std::string& data)
if (_limit && total > _limit) if (_limit && total > _limit)
break; break;
} }
while (received > 0 && total < (int) expected); while (received > 0 && total < static_cast<int>(expected));
if (_debug) if (_debug)
std::cout << "c: INFO Receiving 'XXXX" std::cout << "c: INFO Receiving 'XXXX"

View file

@ -181,7 +181,7 @@ std::string Task::identifier (bool shortened /* = false */) const
void Task::setAsNow (const std::string& att) void Task::setAsNow (const std::string& att)
{ {
char now[16]; char now[16];
snprintf (now, 16, "%u", (unsigned int) time (nullptr)); snprintf (now, 16, "%u", static_cast<unsigned int>(time (nullptr)));
set (att, now); set (att, now);
recalc_urgency = true; recalc_urgency = true;
@ -261,7 +261,7 @@ time_t Task::get_date (const std::string& name) const
{ {
auto i = data.find (name); auto i = data.find (name);
if (i != data.end ()) if (i != data.end ())
return (time_t) strtoul (i->second.c_str (), nullptr, 10); return static_cast<time_t>(strtoul (i->second.c_str (), nullptr, 10));
return 0; return 0;
} }
@ -1065,7 +1065,7 @@ void Task::addAnnotation (const std::string& description)
do do
{ {
key = "annotation_" + format ((int) now); key = "annotation_" + format (static_cast<int>(now));
++now; ++now;
} }
while (has (key)); while (has (key));
@ -1234,7 +1234,7 @@ std::vector <Task> Task::getDependencyTasks () const
int Task::getTagCount () const int Task::getTagCount () const
{ {
auto tags = split (get ("tags"), ','); auto tags = split (get ("tags"), ',');
return (int) tags.size (); return static_cast<int>(tags.size ());
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////

View file

@ -1181,7 +1181,7 @@ Variant& Variant::operator^= (const Variant& other)
switch (other._type) switch (other._type)
{ {
case type_boolean: throw std::string (STRING_VARIANT_EXP_BOOL); case type_boolean: throw std::string (STRING_VARIANT_EXP_BOOL);
case type_integer: _integer = (int) pow (static_cast<double>(_integer), static_cast<double>(other._integer)); break; case type_integer: _integer = static_cast<int>(pow (static_cast<double>(_integer), static_cast<double>(other._integer))); break;
case type_real: throw std::string (STRING_VARIANT_EXP_NON_INT); case type_real: throw std::string (STRING_VARIANT_EXP_NON_INT);
case type_string: throw std::string (STRING_VARIANT_EXP_STRING); case type_string: throw std::string (STRING_VARIANT_EXP_STRING);
case type_date: throw std::string (STRING_VARIANT_EXP_DATE); case type_date: throw std::string (STRING_VARIANT_EXP_DATE);
@ -1285,7 +1285,7 @@ Variant& Variant::operator-= (const Variant& other)
{ {
case type_boolean: right.cast (type_integer); _date -= right._integer; break; case type_boolean: right.cast (type_integer); _date -= right._integer; break;
case type_integer: _date -= right._integer; break; case type_integer: _date -= right._integer; break;
case type_real: _date -= (int) right._real; break; case type_real: _date -= static_cast<int>(right._real); break;
case type_string: throw std::string (STRING_VARIANT_SUB_STRING); case type_string: throw std::string (STRING_VARIANT_SUB_STRING);
case type_date: cast (type_duration); _duration -= right._date; break; case type_date: cast (type_duration); _duration -= right._date; break;
case type_duration: _date -= right._duration; break; case type_duration: _date -= right._duration; break;
@ -1297,7 +1297,7 @@ Variant& Variant::operator-= (const Variant& other)
{ {
case type_boolean: right.cast (type_integer); _duration -= right._integer; break; case type_boolean: right.cast (type_integer); _duration -= right._integer; break;
case type_integer: _duration -= right._integer; break; case type_integer: _duration -= right._integer; break;
case type_real: _duration -= (int) right._real; break; case type_real: _duration -= static_cast<int>(right._real); break;
case type_string: throw std::string (STRING_VARIANT_SUB_STRING); case type_string: throw std::string (STRING_VARIANT_SUB_STRING);
case type_date: throw std::string (STRING_VARIANT_SUB_DATE); case type_date: throw std::string (STRING_VARIANT_SUB_DATE);
case type_duration: _duration -= right._duration; break; case type_duration: _duration -= right._duration; break;
@ -1367,18 +1367,18 @@ Variant& Variant::operator+= (const Variant& other)
case type_date: case type_date:
_type = type_date; _type = type_date;
_date = (unsigned) (int) _real + right._date; _date = static_cast<unsigned>(static_cast<int>(_real)) + right._date;
break; break;
case type_duration: case type_duration:
_type = type_duration; _type = type_duration;
_duration = (unsigned) (int) _real + right._duration; _duration = static_cast<unsigned>(static_cast<int>(_real)) + right._duration;
break; break;
} }
break; break;
case type_string: case type_string:
_string += (std::string) right; _string += std::string(right);
break; break;
case type_date: case type_date:
@ -1386,7 +1386,7 @@ Variant& Variant::operator+= (const Variant& other)
{ {
case type_boolean: right.cast (type_date); _date += right._date; break; case type_boolean: right.cast (type_date); _date += right._date; break;
case type_integer: _date += right._integer; break; case type_integer: _date += right._integer; break;
case type_real: _date += (int) right._real; break; case type_real: _date += static_cast<int>(right._real); break;
case type_string: cast (type_string); _string += right._string; break; case type_string: cast (type_string); _string += right._string; break;
case type_date: throw std::string (STRING_VARIANT_ADD_DATE); case type_date: throw std::string (STRING_VARIANT_ADD_DATE);
case type_duration: _date += right._duration; break; case type_duration: _date += right._duration; break;
@ -1398,7 +1398,7 @@ Variant& Variant::operator+= (const Variant& other)
{ {
case type_boolean: right.cast (type_duration); _duration += right._duration; break; case type_boolean: right.cast (type_duration); _duration += right._duration; break;
case type_integer: _duration += right._integer; break; case type_integer: _duration += right._integer; break;
case type_real: _duration += (int) right._real; break; case type_real: _duration += static_cast<int>(right._real); break;
case type_string: cast (type_string); _string += right._string; break; case type_string: cast (type_string); _string += right._string; break;
case type_date: cast (type_date); _date += right._date; break; case type_date: cast (type_date); _date += right._date; break;
case type_duration: _duration += right._duration; break; case type_duration: _duration += right._duration; break;
@ -1478,7 +1478,7 @@ Variant& Variant::operator*= (const Variant& other)
case type_duration: case type_duration:
_type = type_duration; _type = type_duration;
_duration = (time_t) (unsigned) (int) (_real * static_cast<double>(right._duration)); _duration = static_cast<time_t>(static_cast<unsigned>(static_cast<int>(_real * static_cast<double>(right._duration))));
} }
break; break;
@ -1511,7 +1511,7 @@ Variant& Variant::operator*= (const Variant& other)
case type_boolean: right.cast (type_duration); _duration *= right._duration; break; case type_boolean: right.cast (type_duration); _duration *= right._duration; break;
case type_integer: _duration *= right._integer; break; case type_integer: _duration *= right._integer; break;
case type_real: case type_real:
_duration = (time_t) (unsigned) (int) (static_cast<double>(_duration) * right._real); _duration = static_cast<time_t>(static_cast<unsigned>(static_cast<int>(static_cast<double>(_duration) * right._real)));
break; break;
case type_string: throw std::string (STRING_VARIANT_MUL_DUR_STR); case type_string: throw std::string (STRING_VARIANT_MUL_DUR_STR);
case type_date: throw std::string (STRING_VARIANT_MUL_DUR_DATE); case type_date: throw std::string (STRING_VARIANT_MUL_DUR_DATE);
@ -1571,7 +1571,7 @@ Variant& Variant::operator/= (const Variant& other)
if (right._duration == 0) if (right._duration == 0)
throw std::string (STRING_VARIANT_DIV_ZERO); throw std::string (STRING_VARIANT_DIV_ZERO);
_type = type_duration; _type = type_duration;
_duration = (time_t) (unsigned) (int) (_integer / right._duration); _duration = static_cast<time_t>(static_cast<unsigned>(static_cast<int>(_integer / right._duration)));
break; break;
} }
break; break;
@ -1604,7 +1604,7 @@ Variant& Variant::operator/= (const Variant& other)
if (right._duration == 0) if (right._duration == 0)
throw std::string (STRING_VARIANT_DIV_ZERO); throw std::string (STRING_VARIANT_DIV_ZERO);
_type = type_duration; _type = type_duration;
_duration = (time_t) (unsigned) (int) (_real / right._duration); _duration = static_cast<time_t>(static_cast<unsigned>(static_cast<int>(_real / right._duration)));
break; break;
} }
break; break;
@ -1631,7 +1631,7 @@ Variant& Variant::operator/= (const Variant& other)
case type_real: case type_real:
if (right._real == 0) if (right._real == 0)
throw std::string (STRING_VARIANT_DIV_ZERO); throw std::string (STRING_VARIANT_DIV_ZERO);
_duration = (time_t) (unsigned) (int) (static_cast<double>(_duration) / right._real); _duration = static_cast<time_t>(static_cast<unsigned>(static_cast<int>(static_cast<double>(_duration) / right._real)));
break; break;
case type_string: case type_string:
@ -1830,8 +1830,8 @@ void Variant::cast (const enum type new_type)
_string = temp; _string = temp;
} }
break; break;
case type_date: _date = (time_t) _integer; break; case type_date: _date = static_cast<time_t>(_integer); break;
case type_duration: _duration = (time_t) _integer; break; case type_duration: _duration = static_cast<time_t>(_integer); break;
} }
break; break;
@ -1839,7 +1839,7 @@ void Variant::cast (const enum type new_type)
switch (new_type) switch (new_type)
{ {
case type_boolean: _bool = _real == 0.0 ? false : true; break; case type_boolean: _bool = _real == 0.0 ? false : true; break;
case type_integer: _integer = (int) _real; break; case type_integer: _integer = static_cast<int>(_real); break;
case type_real: break; case type_real: break;
case type_string: case type_string:
{ {
@ -1848,8 +1848,8 @@ void Variant::cast (const enum type new_type)
_string = temp; _string = temp;
} }
break; break;
case type_date: _date = (time_t) (int) _real; break; case type_date: _date = static_cast<time_t>(static_cast<int>(_real)); break;
case type_duration: _duration = (time_t) (int) _real; break; case type_duration: _duration = static_cast<time_t>(static_cast<int>(_real)); break;
} }
break; break;
@ -1863,7 +1863,7 @@ void Variant::cast (const enum type new_type)
_string == "0.0") ? false : true; _string == "0.0") ? false : true;
break; break;
case type_integer: case type_integer:
_integer = (int) strtol (_string.c_str (), nullptr, (_string.substr (0, 2) == "0x" ? 16 : 10)); _integer = static_cast<int>(strtol (_string.c_str (), nullptr, (_string.substr (0, 2) == "0x" ? 16 : 10)));
break; break;
case type_real: _real = strtod (_string.c_str (), nullptr); break; case type_real: _real = strtod (_string.c_str (), nullptr); break;
case type_string: break; case type_string: break;
@ -1914,9 +1914,9 @@ void Variant::cast (const enum type new_type)
switch (new_type) switch (new_type)
{ {
case type_boolean: _bool = _date != 0 ? true : false; break; case type_boolean: _bool = _date != 0 ? true : false; break;
case type_integer: _integer = (int) _date; break; case type_integer: _integer = static_cast<int>(_date); break;
case type_real: _real = static_cast<double>(_date); break; case type_real: _real = static_cast<double>(_date); break;
case type_string: _string = (std::string) *this; break; case type_string: _string = std::string(*this); break;
case type_date: break; case type_date: break;
case type_duration: _duration = _date; break; case type_duration: _duration = _date; break;
} }
@ -1926,9 +1926,9 @@ void Variant::cast (const enum type new_type)
switch (new_type) switch (new_type)
{ {
case type_boolean: _bool = _duration != 0 ? true : false; break; case type_boolean: _bool = _duration != 0 ? true : false; break;
case type_integer: _integer = (int) _duration; break; case type_integer: _integer = static_cast<int>(_duration); break;
case type_real: _real = static_cast<double>(_duration); break; case type_real: _real = static_cast<double>(_duration); break;
case type_string: _string = (std::string) *this; break; case type_string: _string = std::string(*this); break;
case type_date: _date = _duration; break; case type_date: _date = _duration; break;
case type_duration: break; case type_duration: break;
} }

View file

@ -127,10 +127,10 @@ std::string ViewTask::render (std::vector <Task>& data, std::vector <int>& seque
for (unsigned int s = 0; s < sequence.size (); ++s) for (unsigned int s = 0; s < sequence.size (); ++s)
{ {
if ((int)s >= _truncate_lines && _truncate_lines != 0) if (static_cast<int>(s) >= _truncate_lines && _truncate_lines != 0)
break; break;
if ((int)s >= _truncate_rows && _truncate_rows != 0) if (static_cast<int>(s) >= _truncate_rows && _truncate_rows != 0)
break; break;
// Determine minimum and ideal width for this column. // Determine minimum and ideal width for this column.

View file

@ -123,7 +123,7 @@ int main (int argc, char** argv)
std::cout << i << '\n'; std::cout << i << '\n';
// Show the result in string form. // Show the result in string form.
std::cout << (std::string) result std::cout << std::string(result)
<< '\n'; << '\n';
} }

View file

@ -248,7 +248,7 @@ std::string renderAttribute (const std::string& name, const std::string& value,
col->type () == "date" && col->type () == "date" &&
!value.empty()) !value.empty())
{ {
Datetime d ((time_t)strtol (value.c_str (), nullptr, 10)); Datetime d (static_cast<time_t>(strtol (value.c_str (), nullptr, 10)));
if (format.empty()) if (format.empty())
return d.toString (Context::getContext ().config.get ("dateformat")); return d.toString (Context::getContext ().config.get ("dateformat"));

View file

@ -99,7 +99,7 @@ void sort_projects (
{ {
std::map <std::string, int> allProjectsInt; std::map <std::string, int> allProjectsInt;
for (auto& p : allProjects) for (auto& p : allProjects)
allProjectsInt[p.first] = (int) p.second; allProjectsInt[p.first] = static_cast<int>(p.second);
sort_projects (sorted, allProjectsInt); sort_projects (sorted, allProjectsInt);
} }