]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
c++/modules: relax diagnostic about GMF contents
authorPatrick Palka <ppalka@redhat.com>
Tue, 5 Mar 2024 02:32:44 +0000 (21:32 -0500)
committerPatrick Palka <ppalka@redhat.com>
Tue, 5 Mar 2024 02:32:44 +0000 (21:32 -0500)
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 <jason@redhat.com>
gcc/c-family/c.opt
gcc/cp/parser.cc
gcc/doc/invoke.texi
gcc/testsuite/g++.dg/modules/friend-6_a.C

index b7a4a1a68e322e3953f1a13948887b3ce189e912..56cccf2a67bd3a89797106743a9d61939dd05bd4 100644 (file)
@@ -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.
index a310b9e8c07c7791bbcd744b8749e8d11de8584d..e32acfc30a28fa2136acd4f783b47e3fce4ff318 100644 (file)
@@ -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");
                }
            }
        }
index bdf05be387de829f4f5e7fcb4a38142e097c5731..2390d478121cc85e001a635fa13804c36b8b3258 100644 (file)
@@ -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)}
index 7493e8f262fcd1937c0864cedcfc560f09dbb785..13f771088d0a86f228010fc5b8e88fcd353acc9f 100644 (file)
@@ -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 <typename> struct Trans_NS___cxx11_basic_string {
   template <typename> friend class basic_stringbuf;
 };
 template struct Trans_NS___cxx11_basic_string<char>;
-# 6 "" 2
 export module friend_6;