From dbfbd3aa2c1fb6293defcb1ad16099bb8aa4a0cb Mon Sep 17 00:00:00 2001 From: Jason Merrill Date: Thu, 16 May 2024 21:43:20 -0400 Subject: c-family: add -fsearch-include-path The C++ modules code has a -fmodule-header (or -x c++-{user,system}-header) option to specify looking up headers to compile to header units on the usual include paths. I'd like to have the same functionality for full C++20 modules such as module std, which I proposed to live on the include path at bits/std.cc. But this behavior doesn't seem necessarily connected to modules, so I'm proposing a general C/C++ option to specify the behavior of looking in the include path for the input files specified on the command line. Other ideas for the name of the option are very welcome. The libcpp change is to allow -fsearch-include-path{,=user} to find files in the current working directory, like -include. This can be handy for a quick compile of both std.cc and a file that imports it, e.g. g++ -std=c++20 -fmodules -fsearch-include-path bits/std.cc importer.cc gcc/ChangeLog: * doc/cppopts.texi: Document -fsearch-include-path. * doc/invoke.texi: Mention it for modules. gcc/c-family/ChangeLog: * c.opt: Add -fsearch-include-path. * c-opts.cc (c_common_post_options): Handle it. gcc/cp/ChangeLog: * module.cc (module_preprocess_options): Don't override it. libcpp/ChangeLog: * internal.h (search_path_head): Declare. * files.cc (search_path_head): No longer static. * init.cc (cpp_read_main_file): Use it. --- libcpp/files.cc | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) (limited to 'libcpp/files.cc') diff --git a/libcpp/files.cc b/libcpp/files.cc index c63f582..840dffc 100644 --- a/libcpp/files.cc +++ b/libcpp/files.cc @@ -189,9 +189,6 @@ static bool read_file_guts (cpp_reader *pfile, _cpp_file *file, location_t loc, const char *input_charset); static bool read_file (cpp_reader *pfile, _cpp_file *file, location_t loc); -static struct cpp_dir *search_path_head (cpp_reader *, const char *fname, - int angle_brackets, enum include_type, - bool suppress_diagnostic = false); static const char *dir_name_of_file (_cpp_file *file); static void open_file_failed (cpp_reader *pfile, _cpp_file *file, int, location_t); @@ -1081,7 +1078,7 @@ _cpp_mark_file_once_only (cpp_reader *pfile, _cpp_file *file) /* Return the directory from which searching for FNAME should start, considering the directive TYPE and ANGLE_BRACKETS. If there is nothing left in the path, returns NULL. */ -static struct cpp_dir * +struct cpp_dir * search_path_head (cpp_reader *pfile, const char *fname, int angle_brackets, enum include_type type, bool suppress_diagnostic) { -- cgit v1.1