On Sat, Feb 21, 2026 at 06:01:59PM +0900, Jason Merrill wrote:
> On 2/21/26 1:57 PM, Nathaniel Shead wrote:
> > Thanks for the patch!  I guess this is probably small enough it doesn't
> > need copyright assignment (can you confirm, Jason?), but you should
> > consider contributing either via DCO or with copyright assignment; see
> > https://gcc.gnu.org/contribute.html#legal.
> 
> This does seem trivial enough, yes.
> 
> But it also seems that we can do better; if the GCM is importable, we should
> import it so that we get any macros defined.  And as Nathaniel suggested in
> the BZ, if the header itself exists, we could #include instead of import.
> The latter will be more complicated to implement, but the former is just
> 
> import->check_importable (reader)
> 
> Does this adjusted patch look good to you?
> 
> BTW, I don't see the original message, only Nathaniel's reply.

LGTM.

> From 9fb28bc401c4c83ac6946d8ea071baf4995cc38c Mon Sep 17 00:00:00 2001
> From: Jason Merrill <[email protected]>
> Date: Sat, 21 Feb 2026 17:23:30 +0900
> Subject: [PATCH] c++/modules: fix -MG for header units [PR123622]
> To: [email protected]
> 
> With -MG we should allow a nonexistent header unit, as we do with a
> nonexistent #include.  But still import it if available.
> 
>       PR c++/123622
> 
> gcc/cp/ChangeLog:
> 
>       * module.cc (preprocess_module): Check deps.missing_files.
> 
> gcc/testsuite/ChangeLog:
> 
>       * g++.dg/modules/dep-6.C: New test.
> 
> Co-authored-by: <[email protected]>
> ---
>  gcc/cp/module.cc                     | 8 +++++++-
>  gcc/testsuite/g++.dg/modules/dep-6.C | 6 ++++++
>  2 files changed, 13 insertions(+), 1 deletion(-)
>  create mode 100644 gcc/testsuite/g++.dg/modules/dep-6.C
> 
> diff --git a/gcc/cp/module.cc b/gcc/cp/module.cc
> index ccbf124876d..450bc70bc0e 100644
> --- a/gcc/cp/module.cc
> +++ b/gcc/cp/module.cc
> @@ -23319,7 +23319,13 @@ preprocess_module (module_state *module, location_t 
> from_loc,
>             if (!(import->is_module ()
>                   && (import->is_partition () || import->is_exported ()))
>                 && import->loadedness == ML_NONE
> -               && (import->is_header () || !flag_preprocess_only))
> +               && (!flag_preprocess_only
> +                   || (import->is_header ()
> +                       /* Allow a missing/unimportable GCM with -MG.
> +                          FIXME We should also try falling back to #include
> +                          before giving up entirely.  */
> +                       && (!cpp_get_options (reader)->deps.missing_files
> +                           || import->check_importable (reader))))
>               {
>                 unsigned n = dump.push (import);
>                 import->do_import (reader, true);
> diff --git a/gcc/testsuite/g++.dg/modules/dep-6.C 
> b/gcc/testsuite/g++.dg/modules/dep-6.C
> new file mode 100644
> index 00000000000..8a7960585a1
> --- /dev/null
> +++ b/gcc/testsuite/g++.dg/modules/dep-6.C
> @@ -0,0 +1,6 @@
> +// PR c++/123622
> +// { dg-additional-options "-fmodules -M -MG -MF dep-6.d" }
> +
> +import "dep-6.h"; // Must not exist!
> +
> +// { dg-final { scan-file dep-6.d {\nCXX_IMPORTS \+= 
> \./dep-6\.h\.c\+\+-module} } }
> -- 
> 2.53.0
> 

Reply via email to