]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
c++: add module extensions
authorJason Merrill <jason@redhat.com>
Thu, 16 May 2024 20:09:12 +0000 (16:09 -0400)
committerJason Merrill <jason@redhat.com>
Wed, 29 May 2024 13:48:05 +0000 (09:48 -0400)
There is a trend in the broader C++ community to use a different extension
for module interface units, even though (in GCC) they are compiled in the
same way as other source files.  Let's recognize these extensions as C++.

.ixx is the MSVC standard, while the .c*m are supported by Clang.  libc++
standard headers use .cppm, as their other source files use .cpp.
Perhaps libstdc++ might use .ccm for parallel consistency?

One issue with .c++m is that libcpp/mkdeps.cc has been using it for the
phony dependencies to express module dependencies, so I'm changing mkdeps to
something less likely to be an actual file, ".c++-module".

gcc/cp/ChangeLog:

* lang-specs.h: Add module interface extensions.

gcc/ChangeLog:

* doc/invoke.texi: Update module extension docs.

libcpp/ChangeLog:

* mkdeps.cc (make_write): Change .c++m to .c++-module.

gcc/testsuite/ChangeLog:

* g++.dg/modules/dep-1_a.C
* g++.dg/modules/dep-1_b.C
* g++.dg/modules/dep-2.C: Change .c++m to .c++-module.

gcc/cp/lang-specs.h
gcc/doc/invoke.texi
gcc/testsuite/g++.dg/modules/dep-1_a.C
gcc/testsuite/g++.dg/modules/dep-1_b.C
gcc/testsuite/g++.dg/modules/dep-2.C
libcpp/mkdeps.cc

index 7a7f5ff0ab5d932eddd4467683c94bf5fa9b85fb..e5651567a2d13c71cec0333555b19b2858411fc3 100644 (file)
@@ -39,6 +39,12 @@ along with GCC; see the file COPYING3.  If not see
   {".HPP", "@c++-header", 0, 0, 0},
   {".tcc", "@c++-header", 0, 0, 0},
   {".hh",  "@c++-header", 0, 0, 0},
+  /* Module interface unit.  Should there also be a .C counterpart?  */
+  {".ixx", "@c++", 0, 0, 0}, /* MSVC */
+  {".cppm", "@c++", 0, 0, 0}, /* Clang/libc++ */
+  {".cxxm", "@c++", 0, 0, 0},
+  {".c++m", "@c++", 0, 0, 0},
+  {".ccm", "@c++", 0, 0, 0},
   {"@c++-header",
       "%{E|M|MM:cc1plus -E %{fmodules-ts:-fdirectives-only -fmodule-header}"
       "  %(cpp_options) %2 %(cpp_debug_options)}"
index 2cba380718b522f740f36bf7711743a837362124..517a782987d9717b3343baf57bfbebfc25e20a85 100644 (file)
@@ -2317,9 +2317,12 @@ other language.
 C++ source files conventionally use one of the suffixes @samp{.C},
 @samp{.cc}, @samp{.cpp}, @samp{.CPP}, @samp{.c++}, @samp{.cp}, or
 @samp{.cxx}; C++ header files often use @samp{.hh}, @samp{.hpp},
-@samp{.H}, or (for shared template code) @samp{.tcc}; and
-preprocessed C++ files use the suffix @samp{.ii}.  GCC recognizes
-files with these names and compiles them as C++ programs even if you
+@samp{.H}, or (for shared template code) @samp{.tcc};
+preprocessed C++ files use the suffix @samp{.ii}; and C++20 module interface
+units sometimes use @samp{.ixx}, @samp{.cppm}, @samp{.cxxm}, @samp{.c++m},
+or @samp{.ccm}.
+
+GCC recognizes files with these names and compiles them as C++ programs even if you
 call the compiler the same way as for compiling C programs (usually
 with the name @command{gcc}).
 
@@ -37705,13 +37708,10 @@ Modular compilation is @emph{not} enabled with just the
 version selected, although in pre-C++20 versions, it is of course an
 extension.
 
-No new source file suffixes are required or supported.  If you wish to
-use a non-standard suffix (@pxref{Overall Options}), you also need
-to provide a @option{-x c++} option too.@footnote{Some users like to
-distinguish module interface files with a new suffix, such as naming
-the source @code{module.cppm}, which involves
-teaching all tools about the new suffix.  A different scheme, such as
-naming @code{module-m.cpp} would be less invasive.}
+No new source file suffixes are required.  A few suffixes preferred
+for module interface units by other compilers (e.g. @samp{.ixx},
+@samp{.cppm}) are supported, but files with these suffixes are treated
+the same as any other C++ source file.
 
 Compiling a module interface unit produces an additional output (to
 the assembly or object file), called a Compiled Module Interface
index 5ec5dd30f6dc0cd9b26bb12ae13f666479dcd7aa..3e92eeaef9fbae98f6eb886805f2b8d3cb5e9c02 100644 (file)
@@ -4,6 +4,6 @@ export module m:part;
 // { dg-module-cmi m:part }
 
 // All The Backslashes!
-// { dg-final { scan-file dep-1_a.d {\nm:part\.c\+\+m: gcm.cache/m-part\.gcm} } }
+// { dg-final { scan-file dep-1_a.d {\nm:part\.c\+\+-module: gcm.cache/m-part\.gcm} } }
 // { dg-final { scan-file dep-1_a.d {\ngcm.cache/m-part\.gcm:| dep-1_a\.o} } }
-// { dg-final { scan-file dep-1_a.d {\n\.PHONY: m:part\.c\+\+m} } }
+// { dg-final { scan-file dep-1_a.d {\n\.PHONY: m:part\.c\+\+-module} } }
index 7a0794eda5182834e1b066e5e0c435296bb2ddea..265ebfcda64a3650b6c8ce936a6afd380cbb04dc 100644 (file)
@@ -3,8 +3,8 @@ export module m;
 // { dg-module-cmi m }
 
 export import :part;
-// { dg-final { scan-file dep-1_b.d {\ndep-1_b\.s gcm.cache/m\.gcm: m:part\.c\+\+m} } }
-// { dg-final { scan-file dep-1_b.d {\nm\.c\+\+m: gcm.cache/m\.gcm} } }
-// { dg-final { scan-file dep-1_b.d {\n\.PHONY: m\.c\+\+m} } }
+// { dg-final { scan-file dep-1_b.d {\ndep-1_b\.s gcm.cache/m\.gcm: m:part\.c\+\+-module} } }
+// { dg-final { scan-file dep-1_b.d {\nm\.c\+\+-module: gcm.cache/m\.gcm} } }
+// { dg-final { scan-file dep-1_b.d {\n\.PHONY: m\.c\+\+-module} } }
 // { dg-final { scan-file dep-1_b.d {\ngcm.cache/m\.gcm:| dep-1_b.o} } }
-// { dg-final { scan-file dep-1_b.d {\nCXX_IMPORTS \+= m:part\.c\+\+m} } }
+// { dg-final { scan-file dep-1_b.d {\nCXX_IMPORTS \+= m:part\.c\+\+-module} } }
index 096243096e3ef954fe956142986e3883512f5744..2dccab3554d0a9a0450bc76ace725280a17f90e6 100644 (file)
@@ -5,8 +5,8 @@ module m:part;
 // { dg-module-cmi !m:part }
 
 // All The Backslashes!
-// { dg-final { scan-file dep-2.d {\nm:part\.c\+\+m: gcm.cache/m-part\.gcm} } }
+// { dg-final { scan-file dep-2.d {\nm:part\.c\+\+-module: gcm.cache/m-part\.gcm} } }
 // { dg-final { scan-file dep-2.d {\ngcm.cache/m:part\.gcm:| dep-2\.o} } }
-// { dg-final { scan-file dep-2.d {\n\.PHONY: m:part\.c\+\+m} } }
+// { dg-final { scan-file dep-2.d {\n\.PHONY: m:part\.c\+\+-module} } }
 
 // { dg-final { scan-file dep-2.i {\nmodule  m:part;\n} } }
index 4cf0cf09178c7b80cd8468b4c4d3fd30eb819f44..622d0dc2ef8ab06ba0ce77048c54f2ada166345b 100644 (file)
@@ -411,8 +411,7 @@ make_write_vec (const mkdeps::vec<const char *> &vec, FILE *fp,
   return col;
 }
 
-/* Write the dependencies to a Makefile.  If PHONY is true, add
-   .PHONY targets for all the dependencies too.  */
+/* Write the dependencies to a Makefile.  */
 
 static void
 make_write (const cpp_reader *pfile, FILE *fp, unsigned int colmax)
@@ -453,7 +452,7 @@ make_write (const cpp_reader *pfile, FILE *fp, unsigned int colmax)
        column = make_write_name (d->cmi_name, fp, column, colmax);
       fputs (":", fp);
       column++;
-      column = make_write_vec (d->modules, fp, column, colmax, 0, ".c++m");
+      column = make_write_vec (d->modules, fp, column, colmax, 0, ".c++-module");
       fputs ("\n", fp);
     }
 
@@ -463,7 +462,7 @@ make_write (const cpp_reader *pfile, FILE *fp, unsigned int colmax)
        {
          /* module-name : cmi-name */
          column = make_write_name (d->module_name, fp, 0, colmax,
-                                   true, ".c++m");
+                                   true, ".c++-module");
          fputs (":", fp);
          column++;
          column = make_write_name (d->cmi_name, fp, column, colmax);
@@ -471,7 +470,7 @@ make_write (const cpp_reader *pfile, FILE *fp, unsigned int colmax)
 
          column = fprintf (fp, ".PHONY:");
          column = make_write_name (d->module_name, fp, column, colmax,
-                                   true, ".c++m");
+                                   true, ".c++-module");
          fputs ("\n", fp);
        }
 
@@ -488,11 +487,11 @@ make_write (const cpp_reader *pfile, FILE *fp, unsigned int colmax)
          fputs ("\n", fp);
        }
     }
-  
+
   if (d->modules.size ())
     {
       column = fprintf (fp, "CXX_IMPORTS +=");
-      make_write_vec (d->modules, fp, column, colmax, 0, ".c++m");
+      make_write_vec (d->modules, fp, column, colmax, 0, ".c++-module");
       fputs ("\n", fp);
     }
 }