Skip to content

Commit

Permalink
Cleanup clang-tidy issues
Browse files Browse the repository at this point in the history
  • Loading branch information
d-frey committed Nov 16, 2024
1 parent 22ddffc commit e03649d
Show file tree
Hide file tree
Showing 31 changed files with 1,748 additions and 1,635 deletions.
2 changes: 1 addition & 1 deletion include/tao/pq/parameter_traits.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -436,7 +436,7 @@ namespace tao::pq
// generate bytea hex format
constexpr char hex[] = "0123456789abcdef";
auto pos = data.size();
internal::resize_uninitialized( data, pos + 3 + 2 * m_v.size() );
internal::resize_uninitialized( data, pos + 3 + ( 2 * m_v.size() ) );
data[ pos++ ] = '\\';
data[ pos++ ] = '\\';
data[ pos++ ] = 'x';
Expand Down
76 changes: 41 additions & 35 deletions src/lib/pq/connection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

#include <tao/pq/connection.hpp>

#include <algorithm>
#include <cctype>
#include <cstring>
#include <format>
Expand Down Expand Up @@ -76,35 +77,39 @@ namespace tao::pq
{}
};

[[nodiscard]] inline auto isolation_level_extension( const isolation_level il ) -> const char*
namespace
{
switch( il ) {
case isolation_level::default_isolation_level:
return "";
case isolation_level::serializable:
return " ISOLATION LEVEL SERIALIZABLE";
case isolation_level::repeatable_read:
return " ISOLATION LEVEL REPEATABLE READ";
case isolation_level::read_committed:
return " ISOLATION LEVEL READ COMMITTED";
case isolation_level::read_uncommitted:
return " ISOLATION LEVEL READ UNCOMMITTED";
[[nodiscard]] inline auto isolation_level_extension( const isolation_level il ) -> const char*
{
switch( il ) {
case isolation_level::default_isolation_level:
return "";
case isolation_level::serializable:
return " ISOLATION LEVEL SERIALIZABLE";
case isolation_level::repeatable_read:
return " ISOLATION LEVEL REPEATABLE READ";
case isolation_level::read_committed:
return " ISOLATION LEVEL READ COMMITTED";
case isolation_level::read_uncommitted:
return " ISOLATION LEVEL READ UNCOMMITTED";
}
TAO_PQ_UNREACHABLE; // LCOV_EXCL_LINE
}
TAO_PQ_UNREACHABLE; // LCOV_EXCL_LINE
}

[[nodiscard]] inline auto access_mode_extension( const access_mode am ) -> const char*
{
switch( am ) {
case access_mode::default_access_mode:
return "";
case access_mode::read_write:
return " READ WRITE";
case access_mode::read_only:
return " READ ONLY";
[[nodiscard]] inline auto access_mode_extension( const access_mode am ) -> const char*
{
switch( am ) {
case access_mode::default_access_mode:
return "";
case access_mode::read_write:
return " READ WRITE";
case access_mode::read_only:
return " READ ONLY";
}
TAO_PQ_UNREACHABLE; // LCOV_EXCL_LINE
}
TAO_PQ_UNREACHABLE; // LCOV_EXCL_LINE
}

} // namespace

class top_level_transaction final
: public transaction_base
Expand All @@ -113,7 +118,7 @@ namespace tao::pq
top_level_transaction( const std::shared_ptr< pq::connection >& connection, const isolation_level il, const access_mode am )
: transaction_base( connection )
{
this->execute( std::string( "START TRANSACTION" ) + isolation_level_extension( il ) + access_mode_extension( am ) );
this->execute( std::format( "START TRANSACTION{}{}", isolation_level_extension( il ), access_mode_extension( am ) ) );
}

~top_level_transaction() override
Expand All @@ -123,10 +128,10 @@ namespace tao::pq
rollback();
}
// LCOV_EXCL_START
catch( const std::exception& ) {
catch( const std::exception& ) { // NOLINT(bugprone-empty-catch)
// TAO_LOG( WARNING, "unable to rollback transaction, swallowing exception: " + std::string( e.what() ) );
}
catch( ... ) {
catch( ... ) { // NOLINT(bugprone-empty-catch)
// TAO_LOG( WARNING, "unable to rollback transaction, swallowing unknown exception" );
}
// LCOV_EXCL_STOP
Expand Down Expand Up @@ -155,10 +160,14 @@ namespace tao::pq
}
};

[[nodiscard]] constexpr auto is_identifier( const std::string_view value ) noexcept -> bool
namespace
{
return !value.empty() && ( value.find_first_not_of( "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_" ) == std::string_view::npos ) && ( std::isdigit( value[ 0 ] ) == 0 );
}
[[nodiscard]] constexpr auto is_identifier( const std::string_view value ) noexcept -> bool
{
return !value.empty() && ( value.find_first_not_of( "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_" ) == std::string_view::npos ) && ( std::isdigit( value[ 0 ] ) == 0 );
}

} // namespace

} // namespace internal

Expand Down Expand Up @@ -225,10 +234,7 @@ namespace tao::pq
while( true ) {
int timeout_ms = -1;
if( m_timeout ) {
timeout_ms = static_cast< int >( std::chrono::duration_cast< std::chrono::milliseconds >( end - std::chrono::steady_clock::now() ).count() );
if( timeout_ms < 0 ) {
timeout_ms = 0; // LCOV_EXCL_LINE
}
timeout_ms = std::max( static_cast< int >( std::chrono::duration_cast< std::chrono::milliseconds >( end - std::chrono::steady_clock::now() ).count() ), 0 );
}

switch( m_poll( socket(), wait_for_write, timeout_ms ) ) {
Expand Down
44 changes: 33 additions & 11 deletions src/lib/pq/exception.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,10 @@ namespace tao::pq
throw stacked_diagnostics_accessed_without_active_handler( error_message, sql_state );
}
throw diagnostics_exception( error_message, sql_state );

default:
throw sql_error( error_message, sql_state );
}
break;

case '2':
switch( sql_state[ 1 ] ) {
Expand Down Expand Up @@ -426,8 +428,10 @@ namespace tao::pq
throw function_executed_no_return_statement( error_message, sql_state );
}
throw sql_routine_exception( error_message, sql_state );

default:
throw sql_error( error_message, sql_state );
}
break;

case '3':
switch( sql_state[ 1 ] ) {
Expand Down Expand Up @@ -478,8 +482,10 @@ namespace tao::pq

case 'F':
throw invalid_schema_name( error_message, sql_state );

default:
throw sql_error( error_message, sql_state );
}
break;

case '4':
switch( sql_state[ 1 ] ) {
Expand Down Expand Up @@ -632,8 +638,10 @@ namespace tao::pq

case '4':
throw with_check_option_violation( error_message, sql_state );

default:
throw sql_error( error_message, sql_state );
}
break;

case '5':
switch( sql_state[ 1 ] ) {
Expand Down Expand Up @@ -708,15 +716,19 @@ namespace tao::pq
throw duplicate_file( error_message, sql_state );
}
throw system_error( error_message, sql_state );

default:
throw sql_error( error_message, sql_state );
}
break;

case '7':
switch( sql_state[ 1 ] ) {
case '2':
throw snapshot_too_old( error_message, sql_state );

default:
throw sql_error( error_message, sql_state );
}
break;

case 'F':
switch( sql_state[ 1 ] ) {
Expand All @@ -725,8 +737,10 @@ namespace tao::pq
throw lock_file_exists( error_message, sql_state );
}
throw config_file_error( error_message, sql_state );

default:
throw sql_error( error_message, sql_state );
}
break;

case 'H':
switch( sql_state[ 1 ] ) {
Expand Down Expand Up @@ -810,8 +824,10 @@ namespace tao::pq
throw fdw_invalid_descriptor_field_identifier( error_message, sql_state );
}
throw fdw_error( error_message, sql_state );

default:
throw sql_error( error_message, sql_state );
}
break;

case 'P':
switch( sql_state[ 1 ] ) {
Expand All @@ -829,8 +845,10 @@ namespace tao::pq
throw assert_failure( error_message, sql_state );
}
throw plpgsql_error( error_message, sql_state );

default:
throw sql_error( error_message, sql_state );
}
break;

case 'X':
switch( sql_state[ 1 ] ) {
Expand All @@ -842,10 +860,14 @@ namespace tao::pq
throw index_corrupted( error_message, sql_state );
}
throw internal_error( error_message, sql_state );

default:
throw sql_error( error_message, sql_state );
}
break;

default:
throw sql_error( error_message, sql_state );
}
throw sql_error( error_message, sql_state );
// LCOV_EXCL_STOP
}

Expand Down
6 changes: 5 additions & 1 deletion src/lib/pq/internal/poll.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,11 @@ namespace tao::pq::internal
#else

const short events = POLLIN | ( wait_for_write ? POLLOUT : 0 );
pollfd pfd = { socket, events, 0 };
pollfd pfd = {
.fd = socket,
.events = events,
.revents = 0
};
errno = 0;
const auto result = ::poll( &pfd, 1, timeout_ms );
switch( result ) {
Expand Down
4 changes: 3 additions & 1 deletion src/lib/pq/internal/strtox.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,10 @@ namespace tao::pq::internal
else {
throw std::overflow_error( failure_message< T >( input ) );
}

default:
throw std::runtime_error( std::format( "code should be unreachable, errno: {}, input: \"{}\"", errno, input ) ); // LCOV_EXCL_LINE
}
throw std::runtime_error( std::format( "code should be unreachable, errno: {}, input: \"{}\"", errno, input ) ); // LCOV_EXCL_LINE
}

} // namespace
Expand Down
2 changes: 1 addition & 1 deletion src/lib/pq/large_object.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ namespace tao::pq
close();
}
// LCOV_EXCL_START
catch( ... ) {
catch( ... ) { // NOLINT(bugprone-empty-catch)
// TODO: How to handle this case properly?
}
// LCOV_EXCL_STOP
Expand Down
4 changes: 2 additions & 2 deletions src/lib/pq/parameter_traits.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ namespace tao::pq::internal
buffer += data;
break;
}
buffer.append( data.data(), n );
buffer.append( data.data(), n ); // NOLINT(bugprone-suspicious-stringview-data-usage)
buffer += '\\';
buffer += data[ n ];
data.remove_prefix( n + 1 );
Expand All @@ -42,7 +42,7 @@ namespace tao::pq::internal
buffer += data;
return;
}
buffer.append( data.data(), n );
buffer.append( data.data(), n ); // NOLINT(bugprone-suspicious-stringview-data-usage)
buffer += '\\';
buffer += data[ n ];
data.remove_prefix( n + 1 );
Expand Down
2 changes: 1 addition & 1 deletion src/lib/pq/result.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ namespace tao::pq
auto result::get( const std::size_t row, const std::size_t column ) const -> const char*
{
if( is_null( row, column ) ) {
throw std::runtime_error( std::format( "unexpected NULL value in row {} column {}/'{}'", row, column, name( column ).c_str() ) );
throw std::runtime_error( std::format( "unexpected NULL value in row {} column {}/'{}'", row, column, name( column ) ) );
}
return PQgetvalue( m_pgresult.get(), static_cast< int >( row ), static_cast< int >( column ) );
}
Expand Down
6 changes: 3 additions & 3 deletions src/lib/pq/result_traits.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,14 @@ namespace tao::pq
throw std::invalid_argument( "unescape BYTEA failed: " + std::string( value ) );
}

const auto size = input / 2 - 1;
const auto size = ( input / 2 ) - 1;

binary nrv;
internal::resize_uninitialized( nrv, size );

for( std::size_t pos = 0; pos < size; ++pos ) {
const auto high = unhex( value[ 2 + 2 * pos ] );
const auto low = unhex( value[ 2 + 2 * pos + 1 ] );
const auto high = unhex( value[ 2 + ( 2 * pos ) ] );
const auto low = unhex( value[ 2 + ( 2 * pos ) + 1 ] );
nrv[ pos ] = static_cast< std::byte >( ( high << 4 ) | low );
}
return nrv;
Expand Down
2 changes: 1 addition & 1 deletion src/lib/pq/table_writer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ namespace tao::pq
try {
std::ignore = m_transaction->get_result();
}
catch( ... ) {
catch( ... ) { // NOLINT(bugprone-empty-catch)
}
}
}
Expand Down
6 changes: 3 additions & 3 deletions src/lib/pq/transaction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@ namespace tao::pq
rollback();
}
// LCOV_EXCL_START
catch( const std::exception& ) {
catch( const std::exception& ) { // NOLINT(bugprone-empty-catch)
// TAO_LOG( WARNING, "unable to rollback transaction, swallowing exception: " + std::string( e.what() ) );
}
catch( ... ) {
catch( ... ) { // NOLINT(bugprone-empty-catch)
// TAO_LOG( WARNING, "unable to rollback transaction, swallowing unknown exception" );
}
// LCOV_EXCL_STOP
Expand Down Expand Up @@ -75,7 +75,7 @@ namespace tao::pq
rollback();
}
// LCOV_EXCL_START
catch( ... ) {
catch( ... ) { // NOLINT(bugprone-empty-catch)
// TODO: How to handle this case properly?
}
// LCOV_EXCL_STOP
Expand Down
Loading

0 comments on commit e03649d

Please sign in to comment.