]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
c++: Add fix note for how to declare main in a module
authorNathaniel Shead <nathanieloshead@gmail.com>
Wed, 25 Jun 2025 11:24:40 +0000 (21:24 +1000)
committerNathaniel Shead <nathanieloshead@gmail.com>
Fri, 27 Jun 2025 07:37:13 +0000 (17:37 +1000)
This patch adds a note to help users unfamiliar with modules terminology
understand how to declare main in a named module since P3618.

There doesn't appear to be an easy robust location available for "the
start of this declaration" that I could find to attach a fixit to, but
the explanation should suffice.

gcc/cp/ChangeLog:

* decl.cc (grokfndecl): Add explanation of how to attach to
global module.

Signed-off-by: Nathaniel Shead <nathanieloshead@gmail.com>
gcc/cp/decl.cc

index 95bccfbb585ba8d286902f02e0d4c6ef5fe2e53b..4fe97ffbf8f9d01145a49e69e6e0a12239cb5332 100644 (file)
@@ -11330,7 +11330,12 @@ grokfndecl (tree ctype,
        pedwarn (location, OPT_Wpedantic, "cannot declare %<::main%> with a"
                 " linkage specification other than %<extern \"C++\"%>");
       if (module_attach_p ())
-       error_at (location, "cannot attach %<::main%> to a named module");
+       {
+         auto_diagnostic_group adg;
+         error_at (location, "cannot attach %<::main%> to a named module");
+         inform (location, "use %<extern \"C++\"%> to attach it to the "
+                 "global module instead");
+       }
       inlinep = 0;
       publicp = 1;
     }