From: Patrick Palka Date: Tue, 5 Mar 2024 02:32:44 +0000 (-0500) Subject: c++/modules: relax diagnostic about GMF contents X-Git-Tag: basepoints/gcc-15~828 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=08edf85f747b9ac1850f9688c8a1bc7c2bf6b4e5;p=thirdparty%2Fgcc.git c++/modules: relax diagnostic about GMF contents Issuing a hard error when the GMF doesn't consist only of preprocessing directives happens to be inconvenient for automated testcase reduction via cvise. This patch relaxes this diagnostic into a pedwarn that can be disabled with -Wno-global-module. gcc/c-family/ChangeLog: * c.opt (Wglobal-module): New warning. gcc/cp/ChangeLog: * parser.cc (cp_parser_translation_unit): Relax GMF contents error into a pedwarn. gcc/ChangeLog: * doc/invoke.texi (-Wno-global-module): Document. gcc/testsuite/ChangeLog: * g++.dg/modules/friend-6_a.C: Pass -Wno-global-module instead of -Wno-pedantic. Remove now unnecessary preprocessing directives from GMF. Reviewed-by: Jason Merrill --- diff --git a/gcc/c-family/c.opt b/gcc/c-family/c.opt index b7a4a1a68e32..56cccf2a67bd 100644 --- a/gcc/c-family/c.opt +++ b/gcc/c-family/c.opt @@ -802,6 +802,10 @@ Wframe-address C ObjC C++ ObjC++ Var(warn_frame_address) Warning LangEnabledBy(C ObjC C++ ObjC++,Wall) Warn when __builtin_frame_address or __builtin_return_address is used unsafely. +Wglobal-module +C++ ObjC++ Var(warn_global_module) Warning Init(1) +Warn about the global module fragment not containing only preprocessing directives. + Wif-not-aligned C ObjC C++ ObjC++ Var(warn_if_not_aligned) Init(1) Warning Warn when the field in a struct is not aligned. diff --git a/gcc/cp/parser.cc b/gcc/cp/parser.cc index a310b9e8c07c..e32acfc30a28 100644 --- a/gcc/cp/parser.cc +++ b/gcc/cp/parser.cc @@ -5253,9 +5253,9 @@ cp_parser_translation_unit (cp_parser* parser) if (!warned) { warned = true; - error_at (token->location, - "global module fragment contents must be" - " from preprocessor inclusion"); + pedwarn (token->location, OPT_Wglobal_module, + "global module fragment contents must be" + " from preprocessor inclusion"); } } } diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi index bdf05be387de..2390d478121c 100644 --- a/gcc/doc/invoke.texi +++ b/gcc/doc/invoke.texi @@ -256,7 +256,7 @@ in the following sections. -Wdeprecated-copy -Wdeprecated-copy-dtor -Wno-deprecated-enum-enum-conversion -Wno-deprecated-enum-float-conversion -Weffc++ -Wno-elaborated-enum-base --Wno-exceptions -Wextra-semi -Wno-inaccessible-base +-Wno-exceptions -Wextra-semi -Wno-global-module -Wno-inaccessible-base -Wno-inherited-variadic-ctor -Wno-init-list-lifetime -Winvalid-constexpr -Winvalid-imported-macros -Wno-invalid-offsetof -Wno-literal-suffix @@ -4774,6 +4774,12 @@ undefined behavior at runtime. This warning is enabled by default. @item -Wextra-semi @r{(C++, Objective-C++ only)} Warn about redundant semicolons after in-class function definitions. +@opindex Wno-global-module +@opindex Wglobal-module +@item -Wno-global-module @r{(C++ and Objective-C++ only)} +Disable the diagnostic for when the global module fragment of a module +unit does not consist only of preprocessor directives. + @opindex Winaccessible-base @opindex Wno-inaccessible-base @item -Wno-inaccessible-base @r{(C++, Objective-C++ only)} diff --git a/gcc/testsuite/g++.dg/modules/friend-6_a.C b/gcc/testsuite/g++.dg/modules/friend-6_a.C index 7493e8f262fc..13f771088d0a 100644 --- a/gcc/testsuite/g++.dg/modules/friend-6_a.C +++ b/gcc/testsuite/g++.dg/modules/friend-6_a.C @@ -1,11 +1,9 @@ -// { dg-additional-options "-fmodules-ts -Wno-pedantic" } +// { dg-additional-options "-fmodules-ts -Wno-global-module" } // { dg-module-cmi friend_6 } module; -# 1 "" 1 template struct Trans_NS___cxx11_basic_string { template friend class basic_stringbuf; }; template struct Trans_NS___cxx11_basic_string; -# 6 "" 2 export module friend_6;