]> git.ipfire.org Git - thirdparty/gcc.git/commit
driver/c++: add --compile-std-module
authorJason Merrill <jason@redhat.com>
Tue, 11 Nov 2025 10:28:01 +0000 (15:58 +0530)
committerJason Merrill <jason@redhat.com>
Tue, 25 Nov 2025 10:23:23 +0000 (15:53 +0530)
commit3ad2e2d707c3d6b0c6bd8c3ef0df4f7aaee1c3c2
tree8f7c46292467c518becc623594bb7157e406fc16
parentb71a289bd9cac5716f426272a3fbddde00d11a5b
driver/c++: add --compile-std-module

For simple testcases that want to use the std module, it would be useful to
have a reasonably short way to request building the binary module form
before the testcase.  So with this patch users can write

  g++ -std=c++20 -fmodules --compile-std-module mytest.C

I expect this to be particularly useful on godbolt.org, where currently
building a modules testcase requires messing with cmake.  One complication
there is that just adding std.cc to the command line arguments hits the
"cannot specify -o with -S with multiple files" error, so I avoid counting
these added inputs as "multiple files"; in that situation each compile will
output to the same target file, with the user-specified input last so it's
the one that actually ends up in the target after the command completes.

gcc/c-family/ChangeLog:

* c.opt: Add --compile-std-module.

gcc/cp/ChangeLog:

* lang-specs.h: Add @c++-system-module.
* g++spec.cc (lang_specific_driver): Handle --compile-std-module.

gcc/ChangeLog:

* doc/invoke.texi: Document --compile-std-module.
* gcc.cc (struct infile): Add artificial field.
(add_infile): Set it.
(driver::prepare_infiles): Check it.

gcc/testsuite/ChangeLog:

* g++.dg/modules/compile-std1.C: New test.
* g++.dg/modules/modules.exp: Only run it once.
gcc/c-family/c.opt
gcc/cp/g++spec.cc
gcc/cp/lang-specs.h
gcc/doc/invoke.texi
gcc/gcc.cc
gcc/testsuite/g++.dg/modules/compile-std1.C [new file with mode: 0644]
gcc/testsuite/g++.dg/modules/modules.exp