[PATCH 4/4] include: Replace C style casts with static_cast

Rosen Penev rosenp at gmail.com
Sat Aug 3 01:55:58 UTC 2019


Found with Clang's -Wold-style-cast

Signed-off-by: Rosen Penev <rosenp at gmail.com>
---
 include/char_traits | 6 +++---
 include/memory      | 6 +++---
 include/string      | 2 +-
 include/vector      | 2 +-
 4 files changed, 8 insertions(+), 8 deletions(-)

diff --git a/include/char_traits b/include/char_traits
index 36eae36..1d33f39 100644
--- a/include/char_traits
+++ b/include/char_traits
@@ -52,7 +52,7 @@ namespace std{
 		static char_type to_char_type(const int_type & i);
 
 		inline static int_type to_int_type(const char_type & c){
-			return (short int)(unsigned char)c;
+			return static_cast<short int>(static_cast<unsigned char>(c));
 		}
 
 		inline static bool eq_int_type(const int_type & a, const int_type & b){
@@ -71,7 +71,7 @@ namespace std{
 		}
 
 		inline static char_type* move(char_type* s1, const char_type* s2, size_t n){
-			return (char*) memmove(s1, s2, n);
+			return static_cast<char*>(memmove(s1, s2, n));
 		}
 
 		inline static char_type* copy(char_type* s1, const char_type* s2, size_t n){
@@ -82,7 +82,7 @@ namespace std{
 		}
 
 		inline static char_type* assign(char_type* s, size_t n, char_type a){
-			return (char *)memset(s, a, n);
+			return static_cast<char *>(memset(s, a, n));
 		}
 
 		inline static int compare(const char_type* s1, const char_type* s2, size_t n){
diff --git a/include/memory b/include/memory
index 9ce6559..37ac637 100644
--- a/include/memory
+++ b/include/memory
@@ -63,15 +63,15 @@ public:
 
 	//Space for n Ts
 	pointer allocate(size_type n, typename allocator<void>::const_pointer = 0){
-		return (T*)(::operator new( n * sizeof(T) ));
+		return static_cast<T*>(::operator new( n * sizeof(T) ));
 	}
 	void deallocate(pointer p, size_type){
 		::operator delete(p);
 	}
 
 	//Use placement new to engage the constructor
-	void construct(pointer p, const T& val) { new((void*)p) T(val); }
-	void destroy(pointer p){ ((T*)p)->~T(); }	//Call destructor
+	void construct(pointer p, const T& val) { new(static_cast<void*>(p)) T(val); }
+	void destroy(pointer p){ (static_cast<T*>(p))->~T(); }	//Call destructor
 
 	size_type max_size() const _UCXX_USE_NOEXCEPT;
 	template<class U> struct rebind { typedef allocator<U> other; };
diff --git a/include/string b/include/string
index a790715..8cfa8b0 100644
--- a/include/string
+++ b/include/string
@@ -70,7 +70,7 @@ public:
 	typedef typename vector<Ch, A>::reverse_iterator reverse_iterator;
 	typedef typename vector<Ch, A>::const_reverse_iterator const_reverse_iterator;
 
-	static const size_type npos = (size_type)-1;
+	static const size_type npos = static_cast<size_type>(-1);
 
 	explicit _UCXXEXPORT basic_string(const A& al = A()) : vector<Ch, A>(al){ return; }
 
diff --git a/include/vector b/include/vector
index 8310bc1..3cf64ed 100644
--- a/include/vector
+++ b/include/vector
@@ -180,7 +180,7 @@ namespace std{
 		}
 
 		_UCXXEXPORT size_type max_size() const{
-			return ((size_type)(-1)) / sizeof(T);
+			return static_cast<size_type>(-1) / sizeof(T);
 		}
 
 		void downsize(size_type sz);
-- 
2.17.1



More information about the uClibc mailing list