aboutsummaryrefslogtreecommitdiff
path: root/libcpp
diff options
context:
space:
mode:
authorJason Merrill <jason@redhat.com>2024-06-04 22:27:56 -0400
committerJason Merrill <jason@redhat.com>2024-06-07 14:29:46 -0400
commita29f481bbcaf2b196f358122a5f1e45c6869df82 (patch)
treeacffb45579d8e7f8d55a90e6b5f32a56e68fd812 /libcpp
parent5c761395402a730535983a5e49ef1775561ebc61 (diff)
downloadgcc-a29f481bbcaf2b196f358122a5f1e45c6869df82.zip
gcc-a29f481bbcaf2b196f358122a5f1e45c6869df82.tar.gz
gcc-a29f481bbcaf2b196f358122a5f1e45c6869df82.tar.bz2
c++: -include and header unit translation
Within a source file, #include is translated to import if a suitable header unit is available, but this wasn't working with -include. This turned out to be because we suppressed the translation before the beginning of the main file. After removing that, I had to tweak libcpp file handling to accommodate the way it moves from an -include to the main file. gcc/ChangeLog: * doc/invoke.texi (C++ Modules): Mention -include. gcc/cp/ChangeLog: * module.cc (maybe_translate_include): Allow before the main file. libcpp/ChangeLog: * files.cc (_cpp_stack_file): LC_ENTER for -include header unit. gcc/testsuite/ChangeLog: * g++.dg/modules/dashinclude-1_b.C: New test. * g++.dg/modules/dashinclude-1_a.H: New test.
Diffstat (limited to 'libcpp')
-rw-r--r--libcpp/files.cc5
1 files changed, 4 insertions, 1 deletions
diff --git a/libcpp/files.cc b/libcpp/files.cc
index c61df33..78f56e3 100644
--- a/libcpp/files.cc
+++ b/libcpp/files.cc
@@ -1008,7 +1008,10 @@ _cpp_stack_file (cpp_reader *pfile, _cpp_file *file, include_type type,
if (decrement)
pfile->line_table->highest_location--;
- if (file->header_unit <= 0)
+ /* Normally a header unit becomes an __import directive in the current file,
+ but with -include we need something to LC_LEAVE to trigger the file_change
+ hook and continue to the next -include or the main source file. */
+ if (file->header_unit <= 0 || type == IT_CMDLINE)
/* Add line map and do callbacks. */
_cpp_do_file_change (pfile, LC_ENTER, file->path,
/* With preamble injection, start on line zero,