Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mapsme/omim.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/base
diff options
context:
space:
mode:
authorАлександр Зацепин <az@mapswithme.com>2017-05-05 14:41:54 +0300
committerr.kuznetsov <r.kuznetsov@corp.mail.ru>2017-05-19 16:41:33 +0300
commitf940356f49bb4aec878d0061a6884792c6936887 (patch)
treecc0d747faea3319797c6d8ece6085245f1cdcb62 /base
parentbe6178d1dec9bf87e096ed483a8860d38455688c (diff)
[core] Added additional warnings about unused results to string_util to_* method to avoid unexcpected behaviour during converting the strings to int
Diffstat (limited to 'base')
-rw-r--r--base/string_utils.hpp30
1 files changed, 16 insertions, 14 deletions
diff --git a/base/string_utils.hpp b/base/string_utils.hpp
index 8fc2228b40..1ebec6dc13 100644
--- a/base/string_utils.hpp
+++ b/base/string_utils.hpp
@@ -1,6 +1,7 @@
#pragma once
#include "base/buffer_vector.hpp"
+#include "base/macros.hpp"
#include "base/stl_add.hpp"
#include <algorithm>
@@ -337,28 +338,29 @@ bool IsInArray(T(&arr)[N], TT const & t)
/// @name From string to numeric.
//@{
-bool to_int(char const * s, int & i, int base = 10);
-bool to_uint(char const * s, unsigned int & i, int base = 10);
-bool to_uint64(char const * s, uint64_t & i);
-bool to_int64(char const * s, int64_t & i);
-bool to_float(char const * s, float & f);
-bool to_double(char const * s, double & d);
-
-inline bool is_number(std::string const & s)
+WARN_UNUSED_RESULT bool to_int(char const * s, int & i, int base = 10);
+WARN_UNUSED_RESULT bool to_uint(char const * s, unsigned int & i, int base = 10);
+WARN_UNUSED_RESULT bool to_uint64(char const * s, uint64_t & i);
+WARN_UNUSED_RESULT bool to_int64(char const * s, int64_t & i);
+WARN_UNUSED_RESULT bool to_float(char const * s, float & f);
+WARN_UNUSED_RESULT bool to_double(char const * s, double & d);
+
+WARN_UNUSED_RESULT inline bool is_number(std::string const & s)
{
int64_t dummy;
return to_int64(s.c_str(), dummy);
}
-inline bool to_int(std::string const & s, int & i, int base = 10) { return to_int(s.c_str(), i, base); }
-inline bool to_uint(std::string const & s, unsigned int & i, int base = 10)
+WARN_UNUSED_RESULT inline bool to_int(std::string const & s, int & i, int base = 10) { return to_int(s.c_str(), i, base); }
+WARN_UNUSED_RESULT inline bool to_uint(std::string const & s, unsigned int & i, int base = 10)
{
return to_uint(s.c_str(), i, base);
}
-inline bool to_uint64(std::string const & s, uint64_t & i) { return to_uint64(s.c_str(), i); }
-inline bool to_int64(std::string const & s, int64_t & i) { return to_int64(s.c_str(), i); }
-inline bool to_float(std::string const & s, float & f) { return to_float(s.c_str(), f); }
-inline bool to_double(std::string const & s, double & d) { return to_double(s.c_str(), d); }
+
+WARN_UNUSED_RESULT inline bool to_uint64(std::string const & s, uint64_t & i) { return to_uint64(s.c_str(), i); }
+WARN_UNUSED_RESULT inline bool to_int64(std::string const & s, int64_t & i) { return to_int64(s.c_str(), i); }
+WARN_UNUSED_RESULT inline bool to_float(std::string const & s, float & f) { return to_float(s.c_str(), f); }
+WARN_UNUSED_RESULT inline bool to_double(std::string const & s, double & d) { return to_double(s.c_str(), d); }
//@}
/// @name From numeric to string.