Skip to content

Commit

Permalink
Fix more clang-tidy comments.
Browse files Browse the repository at this point in the history
  • Loading branch information
ColinH committed Apr 19, 2024
1 parent b1c716f commit 1316687
Show file tree
Hide file tree
Showing 19 changed files with 60 additions and 34 deletions.
6 changes: 5 additions & 1 deletion include/tao/pegtl/internal/unhex_utility.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,12 @@ namespace TAO_PEGTL_NAMESPACE::internal
}

template< typename I >
[[nodiscard]] constexpr I unhex_string_impl( const char* begin, const char* end, I result = 0 )
[[nodiscard]] constexpr I unhex_string_impl( const char* begin, const char* end )
{
if( begin == end ) {
return 0;
}
I result = unhex_char_impl< I >( *begin++ );
while( begin != end ) {
result <<= 4;
result += unhex_char_impl< I >( *begin++ );
Expand Down
2 changes: 1 addition & 1 deletion src/example/pegtl/iri.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ struct IRI
std::string query;
std::string fragment;

explicit IRI( pegtl::argv_input< pegtl::scan::lf_crlf >& );
explicit IRI( pegtl::argv_input< pegtl::scan::lf_crlf >& in );
};

namespace iri
Expand Down
2 changes: 1 addition & 1 deletion src/example/pegtl/token_input_1.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ struct my_grammar
int main()
{
const std::vector< my_token > v{
{ my_type::beta, "first" },
{ my_type::beta, "first" },
{ my_type::beta, "second" }
};
token_input< my_token > in( v );
Expand Down
2 changes: 1 addition & 1 deletion src/example/pegtl/token_input_2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ struct my_grammar
int main()
{
const std::vector< my_token > v{
{ my_type::beta, "first" },
{ my_type::beta, "first" },
{ my_type::beta, "second" }
};
token_input in( v );
Expand Down
2 changes: 1 addition & 1 deletion src/example/pegtl/uri.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ struct URI
std::string query;
std::string fragment;

explicit URI( pegtl::argv_input< pegtl::scan::lf_crlf >& );
explicit URI( pegtl::argv_input< pegtl::scan::lf_crlf >& in );
};

namespace uri
Expand Down
7 changes: 6 additions & 1 deletion src/test/pegtl/action_apply_2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,12 @@ namespace TAO_PEGTL_NAMESPACE
}

std::size_t count = 0;
text_position pos[] = { { 1, 1, 0 }, { 1, 2, 1 }, { 2, 1, 2 }, { 2, 2, 3 } };
text_position pos[] = {
{1, 1, 0},
{ 1, 2, 1},
{ 2, 1, 2},
{ 2, 2, 3}
};

template< typename Rule >
struct count_action
Expand Down
2 changes: 1 addition & 1 deletion src/test/pegtl/ascii_atomics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ namespace TAO_PEGTL_NAMESPACE
verify_rule< ascii::ranges< 'a', 'z', '4' > >( __LINE__, __FILE__, "", result_type::local_failure, 0 );

for( int i = 0; i < 128; ++i ) {
const int c = char( i );
const auto c = char( i );

const bool is_one = ( c == '#' ) || ( c == 'a' ) || ( c == ' ' );
const bool is_range = ( 20 <= c ) && ( c <= 120 );
Expand Down
2 changes: 1 addition & 1 deletion src/test/pegtl/ascii_classes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ namespace TAO_PEGTL_NAMESPACE
verify_rule< ascii::xdigit >( __LINE__, __FILE__, "", result_type::local_failure, 0 );

for( int i = 0; i < 128; ++i ) {
const int c = char( i );
const auto c = char( i ); // NOLINT(bugprone-signed-char-misuse)

const bool is_blank = ( c == ' ' ) || ( c == '\t' );
const bool is_digit = ( '0' <= c ) && ( c <= '9' );
Expand Down
2 changes: 1 addition & 1 deletion src/test/pegtl/buffer_buffer_common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
namespace TAO_PEGTL_NAMESPACE
{
template< typename Buffer, typename... As >
void test_common( As&&... as )
void test_common( As&&... as ) // NOLINT(readability-function-size)
{
const std::string st = "abcdefghijklmnopqrstuvwxyz";

Expand Down
6 changes: 3 additions & 3 deletions src/test/pegtl/contrib_nested_exceptions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ namespace TAO_PEGTL_NAMESPACE
void test1()
{
try {
throw s1;
throw std::string( s1 );
}
catch( ... ) {
visitor v;
Expand All @@ -60,7 +60,7 @@ namespace TAO_PEGTL_NAMESPACE
void test2()
{
try {
throw s1;
throw std::string( s1 );
}
catch( const std::string& s ) {
visitor v;
Expand All @@ -75,7 +75,7 @@ namespace TAO_PEGTL_NAMESPACE
{
try {
try {
throw s1;
throw std::string( s1 );
}
catch( ... ) {
std::throw_with_nested( std::runtime_error( s2 ) );
Expand Down
4 changes: 2 additions & 2 deletions src/test/pegtl/internal_data_and_size.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,15 @@ namespace TAO_PEGTL_NAMESPACE
static_assert( std::is_same_v< decltype( das.data() ), std::int32_t > );
TAO_PEGTL_TEST_ASSERT( !das );
TAO_PEGTL_TEST_ASSERT( das.empty() );
TAO_PEGTL_TEST_ASSERT( das.size() == 0 );
TAO_PEGTL_TEST_ASSERT( das.size() == 0 ); // NOLINT(readability-container-size-empty)
}
{
internal::data_and_size< std::int32_t, void > das;
static_assert( std::is_same_v< decltype( das.size() ), std::size_t > );
static_assert( std::is_same_v< decltype( das.data() ), const std::int32_t& > );
TAO_PEGTL_TEST_ASSERT( !das );
TAO_PEGTL_TEST_ASSERT( das.empty() );
TAO_PEGTL_TEST_ASSERT( das.size() == 0 );
TAO_PEGTL_TEST_ASSERT( das.size() == 0 ); // NOLINT(readability-container-size-empty)
TAO_PEGTL_TEST_ASSERT( das.pointer() == nullptr );
}
{
Expand Down
13 changes: 9 additions & 4 deletions src/test/pegtl/internal_extract_position.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ namespace TAO_PEGTL_NAMESPACE
return &m_int;
}

[[nodiscard]] test_type_1 current_position() const noexcept
[[nodiscard]] static test_type_1 current_position() noexcept
{
return {};
}
Expand All @@ -46,7 +46,7 @@ namespace TAO_PEGTL_NAMESPACE

struct test_type_4
{
[[nodiscard]] test_type_1 current_position() const noexcept
[[nodiscard]] static test_type_1 current_position() noexcept
{
return {};
}
Expand All @@ -61,7 +61,7 @@ namespace TAO_PEGTL_NAMESPACE
return &m_tok;
}

[[nodiscard]] int current_position() const noexcept
[[nodiscard]] static int current_position() noexcept
{
return 0;
}
Expand All @@ -86,7 +86,7 @@ namespace TAO_PEGTL_NAMESPACE
return &m_tok;
}

[[nodiscard]] int current_position() const noexcept
[[nodiscard]] static int current_position() noexcept
{
return 0;
}
Expand All @@ -98,26 +98,31 @@ namespace TAO_PEGTL_NAMESPACE
test_type_1 t1;
auto e1 = internal::extract_position( t1 );
static_assert( std::is_same_v< decltype( e1 ), test_type_1 > );
(void)e1;
}
{
test_type_2 t2;
decltype( auto ) e2 = internal::extract_position( t2 );
static_assert( std::is_same_v< decltype( e2 ), test_type_1 > );
(void)e2;
}
{
test_type_3 t3;
decltype( auto ) e3 = internal::extract_position( t3 );
static_assert( std::is_same_v< decltype( e3 ), const test_type_1& > );
(void)e3;
}
{
test_type_5 t5;
decltype( auto ) e5 = internal::extract_position( t5 );
static_assert( std::is_same_v< decltype( e5 ), test_type_1 > );
(void)e5;
}
{
test_type_7 t7;
decltype( auto ) e7 = internal::extract_position( t7 );
static_assert( std::is_same_v< decltype( e7 ), const test_type_1& > );
(void)e7;
}
}

Expand Down
14 changes: 7 additions & 7 deletions src/test/pegtl/internal_get_eol_rule_char.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,29 +14,29 @@ using namespace TAO_PEGTL_NAMESPACE;

int main()
{
static_assert( internal::get_eol_rule_char_v< void > == false );
static_assert( !internal::get_eol_rule_char_v< void > );
static_assert( std::is_same_v< decltype( internal::get_eol_rule_char_v< void > ), const bool > );
static_assert( internal::get_eol_rule_char_v< char > == false );
static_assert( !internal::get_eol_rule_char_v< char > );
static_assert( std::is_same_v< decltype( internal::get_eol_rule_char_v< char > ), const bool > );
static_assert( internal::get_eol_rule_char_v< std::string > == false );
static_assert( !internal::get_eol_rule_char_v< std::string > );
static_assert( std::is_same_v< decltype( internal::get_eol_rule_char_v< std::string > ), const bool > );

static_assert( internal::get_eol_rule_char_v< ascii::lf > == '\n' );
static_assert( std::is_same_v< decltype( internal::get_eol_rule_char_v< ascii::lf > ), const char > );
static_assert( internal::get_eol_rule_char_v< ascii::cr_lf > == false );
static_assert( !internal::get_eol_rule_char_v< ascii::cr_lf > );
static_assert( std::is_same_v< decltype( internal::get_eol_rule_char_v< ascii::cr_lf > ), const bool > );

static_assert( internal::get_eol_rule_char_v< utf8::lf > == '\n' );
static_assert( std::is_same_v< decltype( internal::get_eol_rule_char_v< utf8::lf > ), const char > );
static_assert( internal::get_eol_rule_char_v< utf8::cr_lf > == false );
static_assert( !internal::get_eol_rule_char_v< utf8::cr_lf > );
static_assert( std::is_same_v< decltype( internal::get_eol_rule_char_v< utf8::cr_lf > ), const bool > );

static_assert( internal::get_eol_rule_char_v< utf32::lf > == '\n' );
static_assert( std::is_same_v< decltype( internal::get_eol_rule_char_v< utf32::lf > ), const char32_t > );
static_assert( internal::get_eol_rule_char_v< utf32::cr_lf > == false );
static_assert( !internal::get_eol_rule_char_v< utf32::cr_lf > );
static_assert( std::is_same_v< decltype( internal::get_eol_rule_char_v< utf32::cr_lf > ), const bool > );

static_assert( internal::get_eol_rule_char_v< ascii::digit > == false );
static_assert( !internal::get_eol_rule_char_v< ascii::digit > );
static_assert( std::is_same_v< decltype( internal::get_eol_rule_char_v< ascii::digit > ), const bool > );

return 0;
Expand Down
6 changes: 3 additions & 3 deletions src/test/pegtl/internal_peek_ascii.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,17 +51,17 @@ namespace TAO_PEGTL_NAMESPACE
{
const auto pair = peek7::peek( in, 3 );
TAO_PEGTL_TEST_ASSERT( !pair );
TAO_PEGTL_TEST_ASSERT( pair.size() == 0 );
TAO_PEGTL_TEST_ASSERT( pair.empty() );
}
{
const auto pair = peek7::peek( in, 4 );
TAO_PEGTL_TEST_ASSERT( !pair );
TAO_PEGTL_TEST_ASSERT( pair.size() == 0 );
TAO_PEGTL_TEST_ASSERT( pair.empty() );
}
{
const auto pair = peek7::peek( in, 5 );
TAO_PEGTL_TEST_ASSERT( !pair );
TAO_PEGTL_TEST_ASSERT( pair.size() == 0 );
TAO_PEGTL_TEST_ASSERT( pair.empty() );
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/test/pegtl/internal_peek_member.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ namespace TAO_PEGTL_NAMESPACE
int* const global3 = &the_integer;
const int* const global4 = &the_integer;

[[nodiscard]] int method1() const noexcept
[[nodiscard]] int method1() const noexcept // NOLINT(readability-convert-member-functions-to-static)
{
return 503;
}
Expand Down
2 changes: 1 addition & 1 deletion src/test/pegtl/internal_stream_to_string.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ namespace TAO_PEGTL_NAMESPACE
{
void unit_test()
{
TAO_PEGTL_TEST_ASSERT( internal::stream_to_string() == "" );
TAO_PEGTL_TEST_ASSERT( internal::stream_to_string().empty() );
TAO_PEGTL_TEST_ASSERT( internal::stream_to_string( "foo" ) == "foo" );
TAO_PEGTL_TEST_ASSERT( internal::stream_to_string( "foo", 42, "bar" ) == "foo42bar" );
}
Expand Down
5 changes: 5 additions & 0 deletions src/test/pegtl/internal_text_inputs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,10 @@ namespace TAO_PEGTL_NAMESPACE
TAO_PEGTL_TEST_ASSERT( test::equal( in.current_position(), 2, 2, 3 ) );
TAO_PEGTL_TEST_ASSERT( in.direct_position() == in.current_position() );
}
}

void test_02_text()
{
using input_1 = text_view_input< ascii::lf >;
{
input_1 in( "" );
Expand Down Expand Up @@ -238,6 +242,7 @@ namespace TAO_PEGTL_NAMESPACE
void unit_test()
{
test_01_text();
test_02_text();
}

} // namespace TAO_PEGTL_NAMESPACE
Expand Down
2 changes: 1 addition & 1 deletion src/test/pegtl/internal_unwind_guard.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ namespace TAO_PEGTL_NAMESPACE
void test2()
{
int i = 1;
internal::unwind_guard( [ & ]() { i = 2; } ); // Anonymous object.
internal::unwind_guard( [ & ]() { i = 2; } ); // NOLINT(bugprone-unused-raii)
TAO_PEGTL_TEST_ASSERT( i == 2 );
}

Expand Down
13 changes: 10 additions & 3 deletions src/test/pegtl/rule_nested.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,19 @@ namespace TAO_PEGTL_NAMESPACE

void test_success()
{
outer_input in( { { "foo", 1 } } );
outer_input in( {
{"foo", 1}
} );
TAO_PEGTL_TEST_ASSERT( in.size() == 1 );
const auto b = parse< outer_grammar >( in );
TAO_PEGTL_TEST_ASSERT( b );
}

void test_failure1()
{
outer_input in( { { "bar", 1 } } );
outer_input in( {
{"bar", 1}
} );
TAO_PEGTL_TEST_ASSERT( in.size() == 1 );
const auto b = parse< outer_grammar >( in );
TAO_PEGTL_TEST_ASSERT( !b );
Expand All @@ -57,7 +61,10 @@ namespace TAO_PEGTL_NAMESPACE

void test_failure3()
{
outer_input in( { { "foo", 1 }, { "foo", 1 } } );
outer_input in( {
{"foo", 1},
{ "foo", 1}
} );
TAO_PEGTL_TEST_ASSERT( in.size() == 2 );
const auto b = parse< outer_grammar >( in );
TAO_PEGTL_TEST_ASSERT( !b );
Expand Down

0 comments on commit 1316687

Please sign in to comment.