Assert that ParseInt/ParseUint are only used with signed/unsigned numbers respectively
Test: build fails when the signedness is mismatched Test: build succeeds otherwise Change-Id: Idd6b146cc167d4607eafc81dbad6c2a79b167094
This commit is contained in:
parent
e0bc5a9aa2
commit
bc64e50bd7
1 changed files with 3 additions and 0 deletions
|
@ -22,6 +22,7 @@
|
|||
|
||||
#include <limits>
|
||||
#include <string>
|
||||
#include <type_traits>
|
||||
|
||||
namespace android {
|
||||
namespace base {
|
||||
|
@ -33,6 +34,7 @@ namespace base {
|
|||
template <typename T>
|
||||
bool ParseUint(const char* s, T* out, T max = std::numeric_limits<T>::max(),
|
||||
bool allow_suffixes = false) {
|
||||
static_assert(std::is_unsigned<T>::value, "ParseUint can only be used with unsigned types");
|
||||
while (isspace(*s)) {
|
||||
s++;
|
||||
}
|
||||
|
@ -96,6 +98,7 @@ template <typename T>
|
|||
bool ParseInt(const char* s, T* out,
|
||||
T min = std::numeric_limits<T>::min(),
|
||||
T max = std::numeric_limits<T>::max()) {
|
||||
static_assert(std::is_signed<T>::value, "ParseInt can only be used with signed types");
|
||||
while (isspace(*s)) {
|
||||
s++;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue