return nullptr;
}
- if (!spans.init_p ())
- /* Before the main file, don't divert. */
- return nullptr;
-
dump.push (NULL);
dump () && dump ("Checking include translation '%s'", path);
inhibits output of the object file, as header files have no associated
object file.
+Header units can be used in much the same way as precompiled headers
+(@pxref{Precompiled Headers}), but with fewer restrictions: an
+#include that is translated to a header unit import can appear at any
+point in the source file, and multiple header units can be used
+together. In particular, the @option{-include} strategy works: with
+the bits/stdc++.h header used for libstdc++ precompiled headers you
+can
+
+@smallexample
+g++ -fmodules-ts -x c++-system-header -c bits/stdc++.h
+g++ -fmodules-ts -include bits/stdc++.h mycode.C
+@end smallexample
+
+and any standard library #includes in mycode.C will be skipped,
+because the import brought in the whole library. This can be a simple
+way to use modules to speed up compilation without any code changes.
+
The @option{-fmodule-only} option disables generation of the
associated object file for compiling a module interface. Only the CMI
is generated. This option is implied when using the
--- /dev/null
+// Test that include translation works with command-line -include.
+// { dg-additional-options "-fmodules-ts -fdump-lang-module -include $srcdir/g++.dg/modules/dashinclude-1_a.H" }
+
+int main ()
+{
+ return f();
+}
+
+// { dg-final { scan-lang-dump {Translating include to import} module } }
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,