@@ -199,7 +199,7 @@ auto _as(lexeme l)
199199 break ;case lexeme::None: return " (NONE)" ;
200200 break ;default : return " INTERNAL-ERROR" ;
201201 }
202- };
202+ }
203203
204204
205205auto is_operator (lexeme l)
@@ -286,13 +286,13 @@ class token
286286 pos.colno += offset;
287287 }
288288
289- auto position () const -> source_position { return pos; }
289+ auto position () const -> source_position { return pos; }
290290
291- auto length () const -> int { return sv.size (); }
291+ auto length () const -> int { return unsafe_narrow< int >( sv.size () ); }
292292
293- auto type () const -> lexeme { return lex_type; }
293+ auto type () const -> lexeme { return lex_type; }
294294
295- auto set_type (lexeme l) -> void { lex_type = l; }
295+ auto set_type (lexeme l) -> void { lex_type = l; }
296296
297297 auto visit (auto & v, int depth) const
298298 -> void
@@ -307,7 +307,7 @@ class token
307307 )
308308 {
309309 sv.remove_prefix (prefix.size ());
310- pos.colno += prefix.size ();
310+ pos.colno += unsafe_narrow< colno_t >( prefix.size () );
311311 }
312312 }
313313
@@ -816,7 +816,7 @@ auto lex_line(
816816 source_position (lineno, i + 1 ),
817817 type
818818 });
819- i += num-1 ;
819+ i += unsafe_narrow< int >( num-1 ) ;
820820
821821 merge_cpp1_multi_token_fundamental_type_names ();
822822 merge_operator_function_names ();
@@ -1066,7 +1066,7 @@ auto lex_line(
10661066 auto parts = expand_raw_string_literal (opening_seq, closing_seq, closing_strategy, part, errors, source_position (lineno, pos_to_replace + 1 ));
10671067 auto new_part = parts.generate ();
10681068 mutable_line.replace ( pos_to_replace, size_to_replace, new_part );
1069- i += std::ssize (new_part)-1 ;
1069+ i += unsafe_narrow< colno_t >( std::ssize (new_part)-1 ) ;
10701070
10711071 if (parts.is_expanded ()) {
10721072 // raw string was expanded and we need to repeat the processing of this line
@@ -1147,7 +1147,7 @@ auto lex_line(
11471147 auto closing_strategy = end_pos == line.npos ? string_parts::no_ends : string_parts::on_the_end;
11481148 auto size_to_replace = end_pos == line.npos ? std::ssize (line) - i : end_pos - i + std::ssize (rsm.closing_seq );
11491149
1150- if (interpolate_raw_string (rsm.opening_seq , rsm.closing_seq , closing_strategy, part, i, size_to_replace ) ) {
1150+ if (interpolate_raw_string (rsm.opening_seq , rsm.closing_seq , closing_strategy, part, i, unsafe_narrow< int >( size_to_replace) ) ) {
11511151 continue ;
11521152 }
11531153 }
@@ -1164,7 +1164,7 @@ auto lex_line(
11641164 raw_string_multiline.value ().text += raw_string_multiline.value ().closing_seq ;
11651165
11661166 // and position where multiline_raw_string ends (needed for reseting line parsing)
1167- i = end_pos+std::ssize (raw_string_multiline.value ().closing_seq )-1 ;
1167+ i = unsafe_narrow< colno_t >( end_pos+std::ssize (raw_string_multiline.value ().closing_seq )-1 ) ;
11681168
11691169 const auto & text = raw_string_multiline.value ().should_interpolate ? raw_string_multiline.value ().text .substr (1 ) : raw_string_multiline.value ().text ;
11701170 multiline_raw_strings.emplace_back (multiline_raw_string{ text, {lineno, i} });
@@ -1379,7 +1379,9 @@ auto lex_line(
13791379 opening_seq,
13801380 closing_seq,
13811381 string_parts::on_both_ends,
1382- std::string_view (&line[paren_pos+1 ], closing_pos-paren_pos-1 ), i, closing_pos-i+std::ssize (closing_seq))
1382+ std::string_view (&line[paren_pos+1 ], closing_pos-paren_pos-1 ),
1383+ i,
1384+ unsafe_narrow<int >(closing_pos-i+std::ssize (closing_seq)))
13831385 ) {
13841386 continue ;
13851387 }
@@ -1397,12 +1399,14 @@ auto lex_line(
13971399 opening_seq,
13981400 closing_seq,
13991401 string_parts::on_the_beginning,
1400- std::string_view (&line[paren_pos+1 ], std::ssize (line)-(paren_pos+1 )), i, std::ssize (line)-i)
1402+ std::string_view (&line[paren_pos+1 ], std::ssize (line)-(paren_pos+1 )),
1403+ i,
1404+ unsafe_narrow<int >(std::ssize (line)-i))
14011405 ) {
14021406 continue ;
14031407 }
14041408 // skip entire raw string opening sequence R"
1405- i = paren_pos;
1409+ i = unsafe_narrow< int >( paren_pos) ;
14061410
14071411 // if we are on the end of the line we need to add new line char
14081412 if (i+1 == std::ssize (line)) {
@@ -1594,7 +1598,7 @@ auto lex_line(
15941598 } else {
15951599 raw_string_multiline.emplace (raw_string{source_position{lineno, i}, opening_seq, opening_seq, closing_seq });
15961600 // skip entire raw string opening sequence R"
1597- i = paren_pos;
1601+ i = unsafe_narrow< int >( paren_pos) ;
15981602
15991603 // if we are on the end of the line we need to add new line char
16001604 if (i+1 == std::ssize (line)) {
@@ -1842,7 +1846,7 @@ class tokens
18421846
18431847 // Create new map entry for the section starting at this line,
18441848 // and populate its tokens with the tokens in this section
1845- auto lineno = std::distance (std::begin (lines), line);
1849+ auto lineno = unsafe_narrow< lineno_t >( std::distance (std::begin (lines), line) );
18461850
18471851 // If this is generated code, use negative line numbers to
18481852 // inform and assist the printer
0 commit comments