taocpp / PEGTL

Parsing Expression Grammar Template Library
Boost Software License 1.0
1.94k stars 228 forks source link

-Wsign-conversion error in memory_input.hpp #197

Closed 0x8000-0000 closed 4 years ago

0x8000-0000 commented 4 years ago

I am handling the parsing failure as documented in https://github.com/taocpp/PEGTL/blob/master/doc/Inputs-and-Parsing.md#error-reporting and I am encountering this warning at compilation time:

/home/florin/work/sam2/external/PEGTL/include/tao/pegtl/internal/../memory_input.hpp: In instantiation of ‘std::string_view tao::pegtl::memory_input<P, Eol, Source>::line_at(const tao::pegtl::position&) const [with tao::pegtl::tracking_mode P = (tao::pegtl::tracking_mode)0; Eol = tao::pegtl::ascii::eol::lf_crlf; Source = std::__cxx11::basic_string<char>; std::string_view = std::basic_string_view<char>]’:
/home/florin/work/sam2/src/sam2_parser.cpp:227:89:   required from here
/home/florin/work/sam2/external/PEGTL/include/tao/pegtl/internal/../memory_input.hpp:372:55: error: conversion to ‘std::basic_string_view<char>::size_type’ {aka ‘long unsigned int’} from ‘long int’ may change the sign of the result [-Werror=sign-conversion]
          return std::string_view( b, end_of_line( p ) - b );

This is with gcc8 on 9d58962818d69436384044e0a578239548f42a7b .

0x8000-0000 commented 4 years ago
--- a/include/tao/pegtl/memory_input.hpp
+++ b/include/tao/pegtl/memory_input.hpp
@@ -369,7 +369,7 @@ namespace TAO_PEGTL_NAMESPACE
       [[nodiscard]] std::string_view line_at( const TAO_PEGTL_NAMESPACE::position& p ) const noexcept
       {
          const char* b = begin_of_line( p );
-         return std::string_view( b, end_of_line( p ) - b );
+         return std::string_view( b, static_cast<size_t>(end_of_line( p ) - b) );
       }
    };

seems to take care of it.

d-frey commented 4 years ago

Thank you!