From 22a7c30c94322e567e85d01ac3ad9b6948671488 Mon Sep 17 00:00:00 2001 From: Daniel Frey Date: Fri, 28 Apr 2023 16:58:42 +0200 Subject: [PATCH] clang-tidy --- .clang-tidy | 1 + include/tao/json/cbor/events/to_stream.hpp | 30 +++++++++++----------- include/tao/json/cbor/parts_parser.hpp | 25 +++++++++--------- include/tao/json/contrib/deque_traits.hpp | 1 + 4 files changed, 29 insertions(+), 28 deletions(-) diff --git a/.clang-tidy b/.clang-tidy index c70509b3..8b5f4236 100644 --- a/.clang-tidy +++ b/.clang-tidy @@ -29,6 +29,7 @@ Checks: >- performance-*, readability-*, -readability-avoid-const-params-in-decls, + -readability-function-cognitive-complexity, -readability-identifier-length, -readability-magic-numbers, diff --git a/include/tao/json/cbor/events/to_stream.hpp b/include/tao/json/cbor/events/to_stream.hpp index f11d5c81..378243ae 100644 --- a/include/tao/json/cbor/events/to_stream.hpp +++ b/include/tao/json/cbor/events/to_stream.hpp @@ -34,35 +34,35 @@ namespace tao::json::cbor::events void null() { - os.put( char( std::uint8_t( internal::major::OTHER ) + 22 ) ); + os.put( static_cast< char >( static_cast< std::uint8_t >( internal::major::OTHER ) + 22 ) ); } void boolean( const bool v ) { - os.put( char( std::uint8_t( internal::major::OTHER ) + 20 + std::uint8_t( v ) ) ); + os.put( static_cast< char >( static_cast< std::uint8_t >( internal::major::OTHER ) + 20 + static_cast< std::uint8_t >( v ) ) ); } void number( const internal::major m, const std::uint64_t v ) { if( v < 24 ) { - os.put( char( std::uint8_t( m ) + v ) ); + os.put( static_cast< char >( static_cast< std::uint8_t >( m ) + v ) ); } else if( v < 256 ) { - os.put( char( std::uint8_t( m ) + 24 ) ); - os.put( char( v ) ); + os.put( static_cast< char >( static_cast< std::uint8_t >( m ) + 24 ) ); + os.put( static_cast< char >( v ) ); } else if( v < 65536 ) { - os.put( char( std::uint8_t( m ) + 25 ) ); - const std::uint16_t x = json::internal::h_to_be( std::uint16_t( v ) ); + os.put( static_cast< char >( static_cast< std::uint8_t >( m ) + 25 ) ); + const std::uint16_t x = json::internal::h_to_be( static_cast< std::uint16_t >( v ) ); os.write( reinterpret_cast< const char* >( &x ), sizeof( x ) ); } else if( v < 4294967296ULL ) { - os.put( char( std::uint8_t( m ) + 26 ) ); - const std::uint32_t x = json::internal::h_to_be( std::uint32_t( v ) ); + os.put( static_cast< char >( static_cast< std::uint8_t >( m ) + 26 ) ); + const std::uint32_t x = json::internal::h_to_be( static_cast< std::uint32_t >( v ) ); os.write( reinterpret_cast< const char* >( &x ), sizeof( x ) ); } else { - os.put( char( std::uint8_t( m ) + 27 ) ); + os.put( static_cast< char >( static_cast< std::uint8_t >( m ) + 27 ) ); const std::uint64_t x = json::internal::h_to_be( v ); os.write( reinterpret_cast< const char* >( &x ), sizeof( x ) ); } @@ -88,7 +88,7 @@ namespace tao::json::cbor::events std::uint64_t n; std::memcpy( &n, &v, sizeof( n ) ); n = json::internal::h_to_be( n ); - os.put( char( std::uint8_t( internal::major::OTHER ) + 27 ) ); + os.put( static_cast< char >( static_cast< std::uint8_t >( internal::major::OTHER ) + 27 ) ); os.write( reinterpret_cast< const char* >( &n ), sizeof( n ) ); } @@ -106,7 +106,7 @@ namespace tao::json::cbor::events void begin_array() { - os.put( char( std::uint8_t( internal::major::ARRAY ) + internal::minor_mask ) ); + os.put( static_cast< char >( static_cast< std::uint8_t >( internal::major::ARRAY ) + internal::minor_mask ) ); } void begin_array( const std::size_t size ) @@ -119,7 +119,7 @@ namespace tao::json::cbor::events void end_array() { - os.put( char( 0xff ) ); + os.put( static_cast< char >( 0xff ) ); } void end_array( const std::size_t /*unused*/ ) noexcept @@ -127,7 +127,7 @@ namespace tao::json::cbor::events void begin_object() { - os.put( char( std::uint8_t( internal::major::OBJECT ) + internal::minor_mask ) ); + os.put( static_cast< char >( static_cast< std::uint8_t >( internal::major::OBJECT ) + internal::minor_mask ) ); } void begin_object( const std::size_t size ) @@ -145,7 +145,7 @@ namespace tao::json::cbor::events void end_object() { - os.put( char( 0xff ) ); + os.put( static_cast< char >( 0xff ) ); } void end_object( const std::size_t /*unused*/ ) noexcept diff --git a/include/tao/json/cbor/parts_parser.hpp b/include/tao/json/cbor/parts_parser.hpp index 313248e8..63ffb184 100644 --- a/include/tao/json/cbor/parts_parser.hpp +++ b/include/tao/json/cbor/parts_parser.hpp @@ -62,10 +62,10 @@ namespace tao::json::cbor { const auto b = json::internal::peek_uint8( in ); switch( b ) { - case std::uint8_t( major::OTHER ) + 20: - case std::uint8_t( major::OTHER ) + 21: + case static_cast< std::uint8_t >( major::OTHER ) + 20: + case static_cast< std::uint8_t >( major::OTHER ) + 21: in.bump_in_this_line( 1 ); - return bool( b - std::uint8_t( major::OTHER ) - 20 ); + return static_cast< bool >( b - static_cast< std::uint8_t >( major::OTHER ) - 20 ); default: throw pegtl::parse_error( "expected boolean", in ); } @@ -84,8 +84,7 @@ namespace tao::json::cbor template< typename... Ts > explicit basic_parts_parser( Ts&&... ts ) : m_input( std::forward< Ts >( ts )... ) - { - } + {} [[nodiscard]] bool empty() { @@ -94,7 +93,7 @@ namespace tao::json::cbor [[nodiscard]] bool null() { - if( json::internal::peek_uint8( m_input ) == std::uint8_t( internal::major::OTHER ) + 22 ) { + if( json::internal::peek_uint8( m_input ) == static_cast< std::uint8_t >( internal::major::OTHER ) + 22 ) { m_input.bump_in_this_line( 1 ); return true; } @@ -144,7 +143,7 @@ namespace tao::json::cbor [[nodiscard]] std::string_view string_view() { const auto b = json::internal::peek_uint8( m_input ); - if( b != std::uint8_t( internal::major::STRING ) + internal::minor_mask ) { + if( b != static_cast< std::uint8_t >( internal::major::STRING ) + internal::minor_mask ) { throw pegtl::parse_error( "expected definitive string", m_input ); } return internal::read_string_1< V, std::string_view >( m_input ); @@ -153,7 +152,7 @@ namespace tao::json::cbor [[nodiscard]] tao::binary_view binary_view() { const auto b = json::internal::peek_uint8( m_input ); - if( b != std::uint8_t( internal::major::BINARY ) + internal::minor_mask ) { + if( b != static_cast< std::uint8_t >( internal::major::BINARY ) + internal::minor_mask ) { throw pegtl::parse_error( "expected definitive binary", m_input ); } return internal::read_string_1< utf8_mode::trust, tao::binary_view >( m_input ); @@ -171,7 +170,7 @@ namespace tao::json::cbor if( u > 9223372036854775807ULL ) { throw pegtl::parse_error( "positive integer overflow", m_input ); } - return std::int64_t( u ); + return static_cast< std::int64_t >( u ); } [[nodiscard]] std::int64_t number_signed_negative() @@ -180,7 +179,7 @@ namespace tao::json::cbor if( u > 9223372036854775808ULL ) { throw pegtl::parse_error( "negative integer overflow", m_input ); } - return std::int64_t( ~u ); + return static_cast< std::int64_t >( ~u ); } #if defined( _MSC_VER ) @@ -215,11 +214,11 @@ namespace tao::json::cbor { const auto b = json::internal::peek_uint8( m_input ); switch( b ) { - case std::uint8_t( internal::major::OTHER ) + 25: + case static_cast< std::uint8_t >( internal::major::OTHER ) + 25: return internal::read_fp16( m_input ); - case std::uint8_t( internal::major::OTHER ) + 26: + case static_cast< std::uint8_t >( internal::major::OTHER ) + 26: return json::internal::read_big_endian_number< float >( m_input + 1 ); - case std::uint8_t( internal::major::OTHER ) + 27: + case static_cast< std::uint8_t >( internal::major::OTHER ) + 27: return json::internal::read_big_endian_number< double >( m_input + 1 ); default: throw pegtl::parse_error( "expected floating point number", m_input ); diff --git a/include/tao/json/contrib/deque_traits.hpp b/include/tao/json/contrib/deque_traits.hpp index 45b1fdac..2c22d622 100644 --- a/include/tao/json/contrib/deque_traits.hpp +++ b/include/tao/json/contrib/deque_traits.hpp @@ -5,6 +5,7 @@ #define TAO_JSON_CONTRIB_DEQUE_TRAITS_HPP #include +#include #include "../consume.hpp" #include "../forward.hpp"