Bug 120773

Summary: [C++26] P3618R0 - Allow attaching main to the global module
Product: gcc Reporter: Jakub Jelinek <jakub>
Component: c++Assignee: Jakub Jelinek <jakub>
Status: RESOLVED FIXED    
Severity: enhancement CC: daniel.kruegler, nshead, webrown.cpp
Priority: P3 Keywords: c++26
Version: 16.0   
Target Milestone: ---   
Host: Target:
Build: Known to work:
Known to fail: Last reconfirmed: 2025-06-23 00:00:00
Bug Depends on:    
Bug Blocks: 103524, 110338    
Attachments: gcc16-pr120773.patch

Description Jakub Jelinek 2025-06-23 08:59:22 UTC
See <https://wg21.link/P3618R0>.
Comment 1 Andrew Pinski 2025-06-23 09:28:36 UTC
.
Comment 2 Jakub Jelinek 2025-06-23 16:31:38 UTC
Created attachment 61690 [details]
gcc16-pr120773.patch

Untested fix.
Comment 3 GCC Commits 2025-06-24 17:01:03 UTC
The master branch has been updated by Jakub Jelinek <jakub@gcc.gnu.org>:

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

commit r16-1657-ged7fc2b29ead88be30b40ec2c3c51495200b08c4
Author: Jakub Jelinek <jakub@redhat.com>
Date:   Tue Jun 24 19:00:11 2025 +0200

    c++: Implement C++26 P3618R0 - Allow attaching main to the global module [PR120773]
    
    The following patch implements the P3618R0 paper by tweaking pedwarn
    condition, adjusting pedwarn wording, adjusting one testcase and adding 4
    new ones.  The paper was voted in as DR, so it isn't guarded on C++ version.
    
    2025-06-24  Jakub Jelinek  <jakub@redhat.com>
    
            PR c++/120773
            * decl.cc (grokfndecl): Implement C++26 P3618R0 - Allow attaching
            main to the global module.  Only pedwarn for current_lang_name
            other than lang_name_cplusplus and adjust pedwarn wording.
    
            * g++.dg/parse/linkage5.C: Don't expect error on
            extern "C++" int main ();.
            * g++.dg/parse/linkage7.C: New test.
            * g++.dg/parse/linkage8.C: New test.
            * g++.dg/modules/main-2.C: New test.
            * g++.dg/modules/main-3.C: New test.
Comment 4 Jakub Jelinek 2025-06-24 17:02:50 UTC
Implemented for GCC 16.