https://gcc.gnu.org/g:e0587298d5e7a97539b134460c37032e20bfcbba

commit r16-1727-ge0587298d5e7a97539b134460c37032e20bfcbba
Author: Nathaniel Shead <nathanielosh...@gmail.com>
Date:   Wed Jun 25 21:24:40 2025 +1000

    c++: Add fix note for how to declare main in a module
    
    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 <nathanielosh...@gmail.com>

Diff:
---
 gcc/cp/decl.cc | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/gcc/cp/decl.cc b/gcc/cp/decl.cc
index 95bccfbb585b..4fe97ffbf8f9 100644
--- a/gcc/cp/decl.cc
+++ b/gcc/cp/decl.cc
@@ -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;
     }

Reply via email to