From 072fb58c4f1b74c13ac3eb2a4f6caf58e5e86ba7 Mon Sep 17 00:00:00 2001 From: Daniel Frey Date: Fri, 28 Apr 2023 22:49:02 +0200 Subject: [PATCH] clang-tidy --- include/tao/json/contrib/patch.hpp | 2 +- src/example/json/jaxn_to_cplusplus.cpp | 9 ++++----- src/example/json/printf_doubles.cpp | 2 +- src/example/json/validate_integer.cpp | 4 ++-- src/test/json/big_list_of_naughty_strings.cpp | 2 +- src/test/json/cbor.cpp | 18 +++++++++--------- src/test/json/events_binary_to.cpp | 5 ++++- src/test/json/jaxn_ostream.cpp | 10 ++++++++-- src/test/json/jaxn_parts_parser.cpp | 4 +++- src/test/json/msgpack.cpp | 8 ++++---- src/test/json/operators.cpp | 12 ++++++------ src/test/json/validate_event_interfaces.cpp | 14 +++++++------- src/test/json/with_arguments.cpp | 2 +- 13 files changed, 51 insertions(+), 41 deletions(-) diff --git a/include/tao/json/contrib/patch.hpp b/include/tao/json/contrib/patch.hpp index e5840c69..b279a7c5 100644 --- a/include/tao/json/contrib/patch.hpp +++ b/include/tao/json/contrib/patch.hpp @@ -42,7 +42,7 @@ namespace tao::json throw std::runtime_error( internal::format( "json patch 'test' failed for '", path, '\'', json::message_extension( v ) ) ); } auto t = std::move( v.at( from ) ); - v.erase( from ); + v.erase( from ); // NOLINT(clang-analyzer-cplusplus.Move) v.insert( path_pointer, std::move( t ) ); } else if( op == "copy" ) { diff --git a/src/example/json/jaxn_to_cplusplus.cpp b/src/example/json/jaxn_to_cplusplus.cpp index 8101296f..3f28bcf0 100644 --- a/src/example/json/jaxn_to_cplusplus.cpp +++ b/src/example/json/jaxn_to_cplusplus.cpp @@ -11,7 +11,7 @@ namespace tao::json::cplusplus::events { protected: std::ostream& os; - char buffer[ 32 ]; + char buffer[ 32 ] = {}; const std::size_t indent; const std::string eol; @@ -26,7 +26,7 @@ namespace tao::json::cplusplus::events std::size_t len = current_indent; while( len != 0 ) { const auto chunk = ( std::min )( indent, sizeof( buffer ) ); - os.write( buffer, chunk ); + os.write( buffer, static_cast< std::streamsize >( chunk ) ); len -= chunk; } } @@ -47,7 +47,6 @@ namespace tao::json::cplusplus::events public: to_pretty_stream( std::ostream& in_os, const std::size_t in_indent ) : os( in_os ), - buffer(), indent( in_indent ), eol( "\n" ) { @@ -113,9 +112,9 @@ namespace tao::json::cplusplus::events next(); os << "tao::binary({ "; if( !v.empty() ) { - os << "std::byte(" << int( v[ 0 ] ) << ")"; + os << "std::byte(" << static_cast< int >( v[ 0 ] ) << ")"; for( std::size_t j = 1; j < v.size(); ++j ) { - os << ", std::byte(" << int( v[ j ] ) << ")"; + os << ", std::byte(" << static_cast< int >( v[ j ] ) << ")"; } } os.write( " })", 3 ); diff --git a/src/example/json/printf_doubles.cpp b/src/example/json/printf_doubles.cpp index 6344adff..4439bfc3 100644 --- a/src/example/json/printf_doubles.cpp +++ b/src/example/json/printf_doubles.cpp @@ -22,7 +22,7 @@ namespace tao::json::events } char buffer[ 32 ]; const std::size_t n = std::snprintf( buffer, sizeof( buffer ), "%0.2f", v ); - os.write( buffer, n ); + os.write( buffer, static_cast< std::streamsize >( n ) ); } void number( const std::int64_t v ) diff --git a/src/example/json/validate_integer.cpp b/src/example/json/validate_integer.cpp index ac681e1e..61570ea7 100644 --- a/src/example/json/validate_integer.cpp +++ b/src/example/json/validate_integer.cpp @@ -19,13 +19,13 @@ namespace tao::json : public Consumer { static_assert( Max >= Min ); - static_assert( Max <= std::uint64_t( ( std::numeric_limits< std::int64_t >::max )() ), "Max may not be larger than 2^63-1" ); + static_assert( Max <= static_cast< std::uint64_t >( ( std::numeric_limits< std::int64_t >::max )() ), "Max may not be larger than 2^63-1" ); using Consumer::Consumer; void number( const std::int64_t v ) { - if( ( v < std::int64_t( Min ) ) || ( v > std::int64_t( Max ) ) ) { + if( ( v < static_cast< std::int64_t >( Min ) ) || ( v > static_cast< std::int64_t >( Max ) ) ) { throw std::runtime_error( "integer range violated: " + std::to_string( v ) ); } Consumer::number( v ); diff --git a/src/test/json/big_list_of_naughty_strings.cpp b/src/test/json/big_list_of_naughty_strings.cpp index 84f7d024..6fc73651 100644 --- a/src/test/json/big_list_of_naughty_strings.cpp +++ b/src/test/json/big_list_of_naughty_strings.cpp @@ -19,7 +19,7 @@ in.seekg( 0, std::ios::end ); contents.resize( static_cast< std::string::size_type >( in.tellg() ) ); in.seekg( 0, std::ios::beg ); - in.read( &contents[ 0 ], contents.size() ); + in.read( contents.data(), static_cast< std::streamsize >( contents.size() ) ); in.close(); return contents; } diff --git a/src/test/json/cbor.cpp b/src/test/json/cbor.cpp index 2f6ac258..46eae403 100644 --- a/src/test/json/cbor.cpp +++ b/src/test/json/cbor.cpp @@ -62,15 +62,15 @@ namespace tao::json cbor_encode( "\"0\"", "6130" ); - cbor_encode( '"' + std::string( std::size_t( 23 ), 'D' ) + '"', "77" + std::string( std::size_t( 46 ), '4' ) ); - cbor_encode( '"' + std::string( std::size_t( 24 ), 'D' ) + '"', "7818" + std::string( std::size_t( 48 ), '4' ) ); - cbor_encode( '"' + std::string( std::size_t( 255 ), 'D' ) + '"', "78ff" + std::string( std::size_t( 510 ), '4' ) ); - cbor_encode( '"' + std::string( std::size_t( 256 ), 'D' ) + '"', "790100" + std::string( std::size_t( 512 ), '4' ) ); - cbor_encode( '"' + std::string( std::size_t( 65535 ), 'D' ) + '"', "79ffff" + std::string( std::size_t( 131070 ), '4' ) ); - cbor_encode( '"' + std::string( std::size_t( 65536 ), 'D' ) + '"', "7a00010000" + std::string( std::size_t( 131072 ), '4' ) ); - - // cbor_encode( '"' + std::string( std::size_t( 4294967295 ), 'D' ) + '"', "7affffffff" + std::string( std::size_t( 8589934590 ), '4' ) ); // Uses 24GB of RAM. - // cbor_encode( '"' + std::string( std::size_t( 4294967296 ), 'D' ) + '"', "7b0000000100000000" + std::string( std::size_t( 8589934592 ), '4' ) ); // Uses 24GB of RAM. + cbor_encode( '"' + std::string( static_cast< std::size_t >( 23 ), 'D' ) + '"', "77" + std::string( static_cast< std::size_t >( 46 ), '4' ) ); + cbor_encode( '"' + std::string( static_cast< std::size_t >( 24 ), 'D' ) + '"', "7818" + std::string( static_cast< std::size_t >( 48 ), '4' ) ); + cbor_encode( '"' + std::string( static_cast< std::size_t >( 255 ), 'D' ) + '"', "78ff" + std::string( static_cast< std::size_t >( 510 ), '4' ) ); + cbor_encode( '"' + std::string( static_cast< std::size_t >( 256 ), 'D' ) + '"', "790100" + std::string( static_cast< std::size_t >( 512 ), '4' ) ); + cbor_encode( '"' + std::string( static_cast< std::size_t >( 65535 ), 'D' ) + '"', "79ffff" + std::string( static_cast< std::size_t >( 131070 ), '4' ) ); + cbor_encode( '"' + std::string( static_cast< std::size_t >( 65536 ), 'D' ) + '"', "7a00010000" + std::string( static_cast< std::size_t >( 131072 ), '4' ) ); + + // cbor_encode( '"' + std::string( static_cast< std::size_t >( 4294967295 ), 'D' ) + '"', "7affffffff" + std::string( static_cast< std::size_t >( 8589934590 ), '4' ) ); // Uses 24GB of RAM. + // cbor_encode( '"' + std::string( static_cast< std::size_t >( 4294967296 ), 'D' ) + '"', "7b0000000100000000" + std::string( static_cast< std::size_t >( 8589934592 ), '4' ) ); // Uses 24GB of RAM. cbor_encode( "[]", "80" ); cbor_encode( "{}", "a0" ); diff --git a/src/test/json/events_binary_to.cpp b/src/test/json/events_binary_to.cpp index f516d5bc..e68baddd 100644 --- a/src/test/json/events_binary_to.cpp +++ b/src/test/json/events_binary_to.cpp @@ -43,7 +43,10 @@ namespace tao::json test_exception( v ); test_hex( v, "\"\"" ); - v = binary{ std::byte( 0 ), std::byte( 255 ), std::byte( 42 ), std::byte( 99 ) }; + v = binary{ static_cast< std::byte >( 0 ), + static_cast< std::byte >( 255 ), + static_cast< std::byte >( 42 ), + static_cast< std::byte >( 99 ) }; test_base64( v, "\"AP8qYw==\"" ); test_base64url( v, "\"AP8qYw\"" ); diff --git a/src/test/json/jaxn_ostream.cpp b/src/test/json/jaxn_ostream.cpp index 5138836b..8c070177 100644 --- a/src/test/json/jaxn_ostream.cpp +++ b/src/test/json/jaxn_ostream.cpp @@ -38,7 +38,10 @@ namespace tao::json test_simple( INFINITY, "Infinity" ); test_simple( -INFINITY, "-Infinity" ); test_simple( "foo", "\"foo\"" ); - test_simple( std::vector< std::byte >( { std::byte( 1 ), std::byte( 2 ), std::byte( 3 ) } ), "$010203" ); + test_simple( std::vector< std::byte >( { static_cast< std::byte >( 1 ), + static_cast< std::byte >( 2 ), + static_cast< std::byte >( 3 ) } ), + "$010203" ); test_simple( empty_array, "[]" ); test_simple( value::array( {} ), "[]" ); test_simple( value::array( { 1 } ), "[1]" ); @@ -58,7 +61,10 @@ namespace tao::json test_pretty( 42, "42" ); test_pretty( 42.1, "42.1" ); test_pretty( "foo", "\"foo\"" ); - test_pretty( std::vector< std::byte >( { std::byte( 1 ), std::byte( 2 ), std::byte( 3 ) } ), "$010203" ); + test_pretty( std::vector< std::byte >( { static_cast< std::byte >( 1 ), + static_cast< std::byte >( 2 ), + static_cast< std::byte >( 3 ) } ), + "$010203" ); test_pretty( empty_array, "[]" ); test_pretty( value::array( {} ), "[]" ); test_pretty( value::array( { 1 } ), "[\n 1\n]" ); diff --git a/src/test/json/jaxn_parts_parser.cpp b/src/test/json/jaxn_parts_parser.cpp index 537d6de9..0455a37a 100644 --- a/src/test/json/jaxn_parts_parser.cpp +++ b/src/test/json/jaxn_parts_parser.cpp @@ -138,7 +138,9 @@ namespace tao::json } { jaxn::parts_parser p( "$34.00.32", __FUNCTION__ ); - const std::vector< std::byte > z = { std::byte( 0x34 ), std::byte( 0x00 ), std::byte( 0x32 ) }; + const std::vector< std::byte > z = { static_cast< std::byte >( 0x34 ), + static_cast< std::byte >( 0x00 ), + static_cast< std::byte >( 0x32 ) }; TEST_ASSERT( p.binary() == z ); TEST_ASSERT( p.empty() ); } diff --git a/src/test/json/msgpack.cpp b/src/test/json/msgpack.cpp index d2344fd3..c25660c8 100644 --- a/src/test/json/msgpack.cpp +++ b/src/test/json/msgpack.cpp @@ -35,8 +35,8 @@ namespace tao::json msgpack_encode( "\"000\"", "a3303030" ); msgpack_encode( "\"01234567890123456789\"", "b43031323334353637383930313233343536373839" ); msgpack_encode( "\"0123456789012345678901234567890123456789\"", "d92830313233343536373839303132333435363738393031323334353637383930313233343536373839" ); - msgpack_encode( "\"" + std::string( std::size_t( 500 ), 'f' ) + "\"", "da01f4" + std::string( std::size_t( 1000 ), '6' ) ); - msgpack_encode( "\"" + std::string( std::size_t( 70000 ), 'f' ) + "\"", "db00011170" + std::string( std::size_t( 140000 ), '6' ) ); + msgpack_encode( "\"" + std::string( static_cast< std::size_t >( 500 ), 'f' ) + "\"", "da01f4" + std::string( static_cast< std::size_t >( 1000 ), '6' ) ); + msgpack_encode( "\"" + std::string( static_cast< std::size_t >( 70000 ), 'f' ) + "\"", "db00011170" + std::string( static_cast< std::size_t >( 140000 ), '6' ) ); msgpack_encode( "0", "00" ); msgpack_encode( "1", "01" ); msgpack_encode( "127", "7f" ); @@ -123,8 +123,8 @@ namespace tao::json msgpack_decode( "db00000000", "\"\"" ); msgpack_decode( "db0000000138", "\"8\"" ); - msgpack_decode( "da01f4" + std::string( std::size_t( 1000 ), '6' ), "\"" + std::string( std::size_t( 500 ), 'f' ) + "\"" ); - msgpack_decode( "db00011170" + std::string( std::size_t( 140000 ), '6' ), "\"" + std::string( std::size_t( 70000 ), 'f' ) + "\"" ); + msgpack_decode( "da01f4" + std::string( static_cast< std::size_t >( 1000 ), '6' ), "\"" + std::string( static_cast< std::size_t >( 500 ), 'f' ) + "\"" ); + msgpack_decode( "db00011170" + std::string( static_cast< std::size_t >( 140000 ), '6' ), "\"" + std::string( static_cast< std::size_t >( 70000 ), 'f' ) + "\"" ); msgpack_decode( "90", "[]" ); msgpack_decode( "80", "{}" ); diff --git a/src/test/json/operators.cpp b/src/test/json/operators.cpp index 709b2e9c..7a398cb8 100644 --- a/src/test/json/operators.cpp +++ b/src/test/json/operators.cpp @@ -129,8 +129,8 @@ namespace tao::json template< typename N > void test_number() { - const value a( N( 42 ) ); - const value b( N( 43 ) ); + const value a( static_cast< N >( 42 ) ); + const value b( static_cast< N >( 43 ) ); const value pa( &a ); const value pb( &b ); @@ -140,7 +140,7 @@ namespace tao::json test_lt( a, pb ); test_lt( pa, pb ); - test_lt( N( 42 ), b ); + test_lt( static_cast< N >( 42 ), b ); test_lt( 42, b ); test_lt( 42U, b ); test_lt( 42.0, b ); @@ -148,7 +148,7 @@ namespace tao::json test_lt( value( 42U ), b ); test_lt( value( 42.0 ), b ); - test_lt( N( 42 ), pb ); + test_lt( static_cast< N >( 42 ), pb ); test_lt( 42, pb ); test_lt( 42U, pb ); test_lt( 42.0, pb ); @@ -156,7 +156,7 @@ namespace tao::json test_lt( value( 42U ), pb ); test_lt( value( 42.0 ), pb ); - test_lt( a, N( 43 ) ); + test_lt( a, static_cast< N >( 43 ) ); test_lt( a, 43 ); test_lt( a, 43U ); test_lt( a, 43.0 ); @@ -164,7 +164,7 @@ namespace tao::json test_lt( a, value( 43U ) ); test_lt( a, value( 43.0 ) ); - test_lt( pa, N( 43 ) ); + test_lt( pa, static_cast< N >( 43 ) ); test_lt( pa, 43 ); test_lt( pa, 43U ); test_lt( pa, 43.0 ); diff --git a/src/test/json/validate_event_interfaces.cpp b/src/test/json/validate_event_interfaces.cpp index b77cf804..fad027f5 100644 --- a/src/test/json/validate_event_interfaces.cpp +++ b/src/test/json/validate_event_interfaces.cpp @@ -73,9 +73,9 @@ namespace tao::json c->boolean( true ); - c->number( int64_t( 0 ) ); - c->number( uint64_t( 0 ) ); - c->number( double( 0 ) ); + c->number( static_cast< std::int64_t >( 0 ) ); + c->number( static_cast< std::uint64_t >( 0 ) ); + c->number( static_cast< double >( 0 ) ); const char* p = ""; c->string( "" ); @@ -89,15 +89,15 @@ namespace tao::json c->binary( xv ); c->begin_array(); - c->begin_array( std::size_t( 0 ) ); + c->begin_array( static_cast< std::size_t >( 0 ) ); c->element(); c->end_array(); - c->end_array( std::size_t( 0 ) ); + c->end_array( static_cast< std::size_t >( 0 ) ); c->begin_object(); - c->begin_object( std::size_t( 0 ) ); + c->begin_object( static_cast< std::size_t >( 0 ) ); c->key( "" ); c->key( k ); @@ -107,7 +107,7 @@ namespace tao::json c->member(); c->end_object(); - c->end_object( std::size_t( 0 ) ); + c->end_object( static_cast< std::size_t >( 0 ) ); } template< typename Consumer > diff --git a/src/test/json/with_arguments.cpp b/src/test/json/with_arguments.cpp index 2071c2ed..5e980c68 100644 --- a/src/test/json/with_arguments.cpp +++ b/src/test/json/with_arguments.cpp @@ -51,7 +51,7 @@ namespace tao::json { [[nodiscard]] static type_2 as( const value& /*unused*/, const arg_0& /*unused*/, const arg_0& /*unused*/ ) { - return type_2(); + return {}; } };