]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
libcpp: Fix reading from stdin with -fsearch-include-path [PR119756]
authorNathaniel Shead <nathanieloshead@gmail.com>
Sat, 21 Feb 2026 13:32:00 +0000 (00:32 +1100)
committerNathaniel Shead <nathanieloshead@gmail.com>
Sun, 22 Feb 2026 15:25:09 +0000 (02:25 +1100)
When using -fsearch-include-path, we prepend the result of
search_path_head to the provided filenames, which for non-absolute paths
will return "./".  At this point, stdin is represented by the empty
string, and so prepending "./" confuses 'open_file'.  This patch fixes
the issue by treating stdin as-if it were an absolute path.

PR c++/119756

libcpp/ChangeLog:

* files.cc (search_path_head): Also treat empty string (stdin)
as an absolute path.

Signed-off-by: Nathaniel Shead <nathanieloshead@gmail.com>
Reviewed-by: Jason Merrill <jason@redhat.com>
libcpp/files.cc

index 9ab3aae4c9217d6fff48b22962fe03cbb2b55863..c0ccbe9b212af85fcd8d09c033d9c8b11adb3467 100644 (file)
@@ -1095,7 +1095,7 @@ search_path_head (cpp_reader *pfile, const char *fname, int angle_brackets,
   cpp_dir *dir;
   _cpp_file *file;
 
-  if (IS_ABSOLUTE_PATH (fname))
+  if (IS_ABSOLUTE_PATH (fname) || *fname == '\0')
     return &pfile->no_search_path;
 
   /* pfile->buffer is NULL when processing an -include command-line flag.  */