[COMMITTED 01/77] gccrs: Return empty file name for inline string source

[email protected]
Newsgroups gmane.comp.gcc.rust,gmane.comp.gcc.patches
Message-ID <[email protected]>
From: Pierre-Emmanuel Patry <[email protected]>

The compiler would crash if the file name was requested from the lexer
whilst lexing from a non-file source (mainly string sources). Now return
an empty file name instead.

gcc/rust/ChangeLog:

	* lex/rust-lex.h: Return an empty file name when file is missing.

Signed-off-by: Pierre-Emmanuel Patry <[email protected]>
---
 gcc/rust/lex/rust-lex.h | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/gcc/rust/lex/rust-lex.h b/gcc/rust/lex/rust-lex.h
index 8d65a6ddf55..530eafbe545 100644
--- a/gcc/rust/lex/rust-lex.h
+++ b/gcc/rust/lex/rust-lex.h
@@ -207,7 +207,13 @@ public:
   void split_current_token (std::vector<TokenPtr> new_tokens);
 
   Linemap *get_line_map () { return line_map; }
-  std::string get_filename () { return std::string (input.get_filename ()); }
+  std::string get_filename ()
+  {
+    if (input.ok ())
+      return std::string (input.get_filename ());
+    else
+      return "";
+  }
 
 private:
   void start_line (int current_line, int current_column);
-- 
2.50.1
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.