Tested x86_64-pc-linux-gnu, will apply to trunk with the rest of the patch series.
-- 8< -- At this point there doesn't seem to be much reason not to have modules support enabled by default in C++20, and it's good get more test coverage to find corner case bugs like some I fixed recently. It also seems to make more sense to use the spelling -fmodules rather than -fmodules-ts, much like we moved from -fconcepts-ts to -fconcepts. The old spelling is still accepted for backward compatibility. gcc/ChangeLog: * doc/invoke.texi: Modules are now enabled by default in C++20. Change advertised flag from -fmodules-ts to -fmodules. gcc/c-family/ChangeLog: * c.opt: Change advertised flag from -fmodules-ts to -fmodules. * c-opts.cc (c_common_post_options): Enable modules by default in C++20. gcc/testsuite/ChangeLog: * g++.dg/template/error25.C: Adjust 'export' diagnostic. * g++.old-deja/g++.benjamin/tem05.C: Likewise. * g++.old-deja/g++.pt/export1.C: Likewise. * g++.dg/pch/pch.exp: Specify -fno-modules. --- gcc/doc/invoke.texi | 32 +++++++++---------- gcc/c-family/c.opt | 10 +++--- gcc/c-family/c-opts.cc | 6 +++- gcc/testsuite/g++.dg/template/error25.C | 2 +- .../g++.old-deja/g++.benjamin/tem05.C | 8 ++--- gcc/testsuite/g++.old-deja/g++.pt/export1.C | 2 +- gcc/testsuite/g++.dg/pch/pch.exp | 2 +- 7 files changed, 32 insertions(+), 30 deletions(-) diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi index b27e85bc38a..29fd99fff92 100644 --- a/gcc/doc/invoke.texi +++ b/gcc/doc/invoke.texi @@ -223,7 +223,7 @@ in the following sections. -fno-implicit-templates -fno-implicit-inline-templates -fno-implement-inlines --fmodule-header@r{[}=@var{kind}@r{]} -fmodule-only -fmodules-ts +-fmodule-header@r{[}=@var{kind}@r{]} -fmodule-only -fmodules -fmodule-implicit-inline -fno-module-lazy -fmodule-mapper=@var{specification} @@ -3501,14 +3501,12 @@ To save space, do not emit out-of-line copies of inline functions controlled by @code{#pragma implementation}. This causes linker errors if these functions are not inlined everywhere they are called. -@opindex fmodules-ts -@opindex fno-modules-ts -@item -fmodules-ts -@itemx -fno-modules-ts -Enable support for C++20 modules (@pxref{C++ Modules}). The -@option{-fno-modules-ts} is usually not needed, as that is the -default. Even though this is a C++20 feature, it is not currently -implicitly enabled by selecting that standard version. +@opindex fmodules +@opindex fno-modules +@item -fmodules +@itemx -fno-modules +Enable support for C++20 modules (@pxref{C++ Modules}). This flag is +enabled by default for C++20 and above. @opindex fmodule-header @item -fmodule-header @@ -38004,9 +38002,9 @@ affected by how you partition header files into header units. @end table -Modular compilation is @emph{not} enabled with just the -@option{-std=c++20} option. You must explicitly enable it with the -@option{-fmodules-ts} option. It is independent of the language +Modular compilation is enabled with the @option{-std=c++20} option. +You can also enable or disable it explicitly with the +@option{-fmodules} option. It is independent of the language version selected, although in pre-C++20 versions, it is of course an extension. @@ -38024,7 +38022,7 @@ Acyclic Graph (DAG). You must build imports before the importer. Header files may themselves be compiled to header units, which are a transitional ability aiming at faster compilation. The @option{-fmodule-header} option is used to enable this, and implies -the @option{-fmodules-ts} option. These CMIs are named by the fully +the @option{-fmodules} option. These CMIs are named by the fully resolved underlying header file, and thus may be a complete pathname containing subdirectories. If the header file is found at an absolute pathname, the CMI location is still relative to a CMI root directory. @@ -38033,7 +38031,7 @@ As header files often have no suffix, you commonly have to specify a @option{-x} option to tell the compiler the source is a header file. You may use @option{-x c++-header}, @option{-x c++-user-header} or @option{-x c++-system-header}. When used in conjunction with -@option{-fmodules-ts}, these all imply an appropriate +@option{-fmodules}, these all imply an appropriate @option{-fmodule-header} option. The latter two variants use the user or system include path to search for the file specified. This allows you to, for instance, compile standard library header files as @@ -38056,8 +38054,8 @@ 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 +g++ -fmodules -x c++-system-header -c bits/stdc++.h +g++ -fmodules -include bits/stdc++.h mycode.C @end smallexample and any standard library #includes in mycode.C will be skipped, @@ -38244,7 +38242,7 @@ preprocessed header; the simplest way to do that is compiling the @option{-fmodule-header}. @smallexample -g++ -fmodules-ts -E my-header.hh -o my-header.ii +g++ -fmodules -E my-header.hh -o my-header.ii g++ -c -fmodule-header my-header.ii @end smallexample diff --git a/gcc/c-family/c.opt b/gcc/c-family/c.opt index 6056dbde4b4..ade49b8cb65 100644 --- a/gcc/c-family/c.opt +++ b/gcc/c-family/c.opt @@ -1997,12 +1997,12 @@ flax-vector-conversions C ObjC C++ ObjC++ Var(flag_lax_vector_conversions) Allow implicit conversions between vectors with differing numbers of subparts and/or differing element types. -fmodules-ts -C++ ObjC++ Var(flag_modules) Integer Init(0) -Enable C++ modules-ts (experimental). +fmodules +C++ ObjC++ Var(flag_modules) Integer +Enable C++20 Modules (experimental). -fno-modules -C++ ObjC++ Undocumented RejectNegative Var(flag_modules,0) Integer +fmodules-ts +C++ ObjC++ Alias(fmodules) Undocumented ;; undocumented fmodule-header diff --git a/gcc/c-family/c-opts.cc b/gcc/c-family/c-opts.cc index c7115e63ce7..4be6259979d 100644 --- a/gcc/c-family/c-opts.cc +++ b/gcc/c-family/c-opts.cc @@ -1183,7 +1183,11 @@ c_common_post_options (const char **pfilename) /* C++20 is the final version of concepts. We still use -fconcepts to know when concepts are enabled. */ if (cxx_dialect >= cxx20) - flag_concepts = 1; + { + flag_concepts = 1; + if (!OPTION_SET_P (flag_modules)) + flag_modules = true; + } /* Enable lifetime extension of range based for temporaries for C++23. Diagnose -std=c++23 -fno-range-for-ext-temps. */ diff --git a/gcc/testsuite/g++.dg/template/error25.C b/gcc/testsuite/g++.dg/template/error25.C index 77b59cd7ca2..6aaf67471b5 100644 --- a/gcc/testsuite/g++.dg/template/error25.C +++ b/gcc/testsuite/g++.dg/template/error25.C @@ -12,5 +12,5 @@ extern void f2 (); template<> extern void f2<void> (); // { dg-error "explicit template specialization cannot have a storage class" } -export template<class T> // { dg-warning "keyword 'export'" } +export template<class T> // { dg-message "'export'" } static void* f3 (); diff --git a/gcc/testsuite/g++.old-deja/g++.benjamin/tem05.C b/gcc/testsuite/g++.old-deja/g++.benjamin/tem05.C index 7b6b955383b..81fb5c4c069 100644 --- a/gcc/testsuite/g++.old-deja/g++.benjamin/tem05.C +++ b/gcc/testsuite/g++.old-deja/g++.benjamin/tem05.C @@ -18,7 +18,7 @@ // 1 // template definition -export template <class T> // { dg-warning "" } +export template <class T> // { dg-message "export" } bool templ_one(T a) { if (a > 0) return true; @@ -41,15 +41,15 @@ public: template <class T2> bool compare_ge(T2 test); }; -export template <class T> // { dg-warning "" } +export template <class T> // { dg-message "export" } const bool X_one<T>::is_specialized = false; -export template <class T> // { dg-warning "" } +export template <class T> // { dg-message "export" } unsigned short X_one<T>::ret_id() { return id; } -export template <class T2> // { dg-warning "" } +export template <class T2> // { dg-message "export" } bool compare_ge(T2 test) { if (test > type) // { dg-error "" } .* return true; diff --git a/gcc/testsuite/g++.old-deja/g++.pt/export1.C b/gcc/testsuite/g++.old-deja/g++.pt/export1.C index 53e7e9b160c..e79785424d2 100644 --- a/gcc/testsuite/g++.old-deja/g++.pt/export1.C +++ b/gcc/testsuite/g++.old-deja/g++.pt/export1.C @@ -15,4 +15,4 @@ return 0; } template <class T> class Y; -export template <class T> class X; // { dg-warning "" } export not implemented +export template <class T> class X; // { dg-message "export" } export not implemented diff --git a/gcc/testsuite/g++.dg/pch/pch.exp b/gcc/testsuite/g++.dg/pch/pch.exp index a443e8fc392..5e3e9b1fdd2 100644 --- a/gcc/testsuite/g++.dg/pch/pch.exp +++ b/gcc/testsuite/g++.dg/pch/pch.exp @@ -31,7 +31,7 @@ set old_dg_do_what_default "${dg-do-what-default}" foreach test [lsort [glob -nocomplain $srcdir/$subdir/*.C]] { # We don't try to use the loop-optimizing options, since they are highly # unlikely to make any difference to PCH. - dg-pch $subdir $test [list "-g" "-O2 -g" "-O2"] ".H" + dg-flags-pch $subdir $test "-fno-modules" [list "-g" "-O2 -g" "-O2"] ".H" } set dg-do-what-default "$old_dg_do_what_default" -- 2.46.2