From 5cac962f180663341367a78aa8b39269935a3264 Mon Sep 17 00:00:00 2001 From: hvellyr Date: Wed, 25 May 2016 09:16:01 +0200 Subject: [PATCH] Fix compiler warning about "old style cast" --- example/calc.cc | 4 ++-- example/calc2.cc | 4 ++-- lint/httplib.h | 2 +- peglib.h | 4 ++-- test/test.cc | 4 ++-- 5 files changed, 9 insertions(+), 9 deletions(-) diff --git a/example/calc.cc b/example/calc.cc index 2f8c01f..99caeb6 100644 --- a/example/calc.cc +++ b/example/calc.cc @@ -46,8 +46,8 @@ int main(int argc, const char** argv) parser["EXPRESSION"] = reduce; parser["TERM"] = reduce; - parser["TERM_OPERATOR"] = [](const SemanticValues& sv) { return (char)*sv.c_str(); }; - parser["FACTOR_OPERATOR"] = [](const SemanticValues& sv) { return (char)*sv.c_str(); }; + parser["TERM_OPERATOR"] = [](const SemanticValues& sv) { return static_cast(*sv.c_str()); }; + parser["FACTOR_OPERATOR"] = [](const SemanticValues& sv) { return static_cast(*sv.c_str()); }; parser["NUMBER"] = [](const SemanticValues& sv) { return atol(sv.c_str()); }; auto expr = argv[1]; diff --git a/example/calc2.cc b/example/calc2.cc index d0e1a0f..59dd234 100644 --- a/example/calc2.cc +++ b/example/calc2.cc @@ -49,8 +49,8 @@ int main(int argc, const char** argv) EXPRESSION <= seq(TERM, zom(seq(TERM_OPERATOR, TERM))), reduce; TERM <= seq(FACTOR, zom(seq(FACTOR_OPERATOR, FACTOR))), reduce; FACTOR <= cho(NUMBER, seq(chr('('), EXPRESSION, chr(')'))); - TERM_OPERATOR <= cls("+-"), [](const SemanticValues& sv) { return (char)*sv.c_str(); }; - FACTOR_OPERATOR <= cls("*/"), [](const SemanticValues& sv) { return (char)*sv.c_str(); }; + TERM_OPERATOR <= cls("+-"), [](const SemanticValues& sv) { return static_cast(*sv.c_str()); }; + FACTOR_OPERATOR <= cls("*/"), [](const SemanticValues& sv) { return static_cast(*sv.c_str()); }; NUMBER <= oom(cls("0-9")), [](const SemanticValues& sv) { return atol(sv.c_str()); }; auto expr = argv[1]; diff --git a/lint/httplib.h b/lint/httplib.h index ad47a21..f3e109e 100644 --- a/lint/httplib.h +++ b/lint/httplib.h @@ -245,7 +245,7 @@ socket_t create_socket(const char* host, int port, Fn fn) // Make 'reuse address' option available int yes = 1; - setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, (char*)&yes, sizeof(yes)); + setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, reinterpret_cast(&yes), sizeof(yes)); // bind or connect if (fn(sock, *rp)) { diff --git a/peglib.h b/peglib.h index e2851f7..0a60a06 100644 --- a/peglib.h +++ b/peglib.h @@ -348,7 +348,7 @@ public: Action& operator=(const Action& rhs) = default; operator bool() const { - return (bool)fn_; + return bool(fn_); } any operator()(const SemanticValues& sv, any& dt) const { @@ -1518,7 +1518,7 @@ inline void DefinitionReference::accept(Visitor& v) { v.visit(*this); } inline void Whitespace::accept(Visitor& v) { v.visit(*this); } inline void AssignIDToDefinition::visit(Holder& ope) { - auto p = (void*)ope.outer_; + auto p = static_cast(ope.outer_); if (ids.count(p)) { return; } diff --git a/test/test.cc b/test/test.cc index b18517d..5c93bbd 100644 --- a/test/test.cc +++ b/test/test.cc @@ -551,8 +551,8 @@ TEST_CASE("Calculator test3", "[general]") // Setup actions parser["EXPRESSION"] = reduce; parser["TERM"] = reduce; - parser["TERM_OPERATOR"] = [](const SemanticValues& sv) { return (char)*sv.c_str(); }; - parser["FACTOR_OPERATOR"] = [](const SemanticValues& sv) { return (char)*sv.c_str(); }; + parser["TERM_OPERATOR"] = [](const SemanticValues& sv) { return static_cast(*sv.c_str()); }; + parser["FACTOR_OPERATOR"] = [](const SemanticValues& sv) { return static_cast(*sv.c_str()); }; parser["NUMBER"] = [](const SemanticValues& sv) { return stol(sv.str(), nullptr, 10); }; // Parse