Skip to content

Commit

Permalink
clang-tidy
Browse files Browse the repository at this point in the history
  • Loading branch information
d-frey committed Apr 28, 2023
1 parent b16af2e commit 072fb58
Show file tree
Hide file tree
Showing 13 changed files with 51 additions and 41 deletions.
2 changes: 1 addition & 1 deletion include/tao/json/contrib/patch.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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" ) {
Expand Down
9 changes: 4 additions & 5 deletions src/example/json/jaxn_to_cplusplus.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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;
}
}
Expand All @@ -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" )
{
Expand Down Expand Up @@ -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 );
Expand Down
2 changes: 1 addition & 1 deletion src/example/json/printf_doubles.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 )
Expand Down
4 changes: 2 additions & 2 deletions src/example/json/validate_integer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
Expand Down
2 changes: 1 addition & 1 deletion src/test/json/big_list_of_naughty_strings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
18 changes: 9 additions & 9 deletions src/test/json/cbor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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" );
Expand Down
5 changes: 4 additions & 1 deletion src/test/json/events_binary_to.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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\"" );
Expand Down
10 changes: 8 additions & 2 deletions src/test/json/jaxn_ostream.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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]" );
Expand All @@ -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]" );
Expand Down
4 changes: 3 additions & 1 deletion src/test/json/jaxn_parts_parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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() );
}
Expand Down
8 changes: 4 additions & 4 deletions src/test/json/msgpack.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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" );
Expand Down Expand Up @@ -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", "{}" );
Expand Down
12 changes: 6 additions & 6 deletions src/test/json/operators.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
Expand All @@ -140,31 +140,31 @@ 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 );
test_lt( value( 42 ), b );
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 );
test_lt( value( 42 ), pb );
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 );
test_lt( a, value( 43 ) );
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 );
Expand Down
14 changes: 7 additions & 7 deletions src/test/json/validate_event_interfaces.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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( "" );
Expand All @@ -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 );
Expand All @@ -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 >
Expand Down
2 changes: 1 addition & 1 deletion src/test/json/with_arguments.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 {};
}
};

Expand Down

0 comments on commit 072fb58

Please sign in to comment.