[gcc r14-7937] gccrs: Improve byte vector to string conversion

Arthur Cohen cohenarthur@gcc.gnu.org
Tue Jan 16 18:08:52 GMT 2024


https://gcc.gnu.org/g:750ac3263c8db064b1d6b3ae33ec6a2036e38bb8

commit r14-7937-g750ac3263c8db064b1d6b3ae33ec6a2036e38bb8
Author: Owen Avery <powerboat9.gamer@gmail.com>
Date:   Wed Aug 2 16:45:42 2023 -0400

    gccrs: Improve byte vector to string conversion
    
    gcc/rust/ChangeLog:
    
            * expand/rust-macro-builtins.cc
            (MacroBuiltin::include_str_handler): Use vector::data.
    
    Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>

Diff:
---
 gcc/rust/expand/rust-macro-builtins.cc | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

diff --git a/gcc/rust/expand/rust-macro-builtins.cc b/gcc/rust/expand/rust-macro-builtins.cc
index 718d740b1dc..b36a46f0aff 100644
--- a/gcc/rust/expand/rust-macro-builtins.cc
+++ b/gcc/rust/expand/rust-macro-builtins.cc
@@ -576,10 +576,8 @@ MacroBuiltin::include_str_handler (location_t invoc_locus,
   if (expect_single)
     rust_error_at (invoc_locus, "%s was not a valid utf-8 file",
 		   target_filename.c_str ());
-  else if (!bytes.empty ())
-    str = std::string ((const char *) &bytes[0], bytes.size ());
   else
-    return tl::nullopt;
+    str = std::string ((const char *) bytes.data (), bytes.size ());
 
   auto node = AST::SingleASTNode (make_string (invoc_locus, str));
   auto str_tok = make_token (Token::make_string (invoc_locus, std::move (str)));


More information about the Gcc-cvs mailing list