https://github.com/ashwinbanwari created https://github.com/llvm/llvm-project/pull/146461
Remove the prior warning for attaching extern "C++" to main. >From 845f99834c6c9a78c05396a0337051273b1ae138 Mon Sep 17 00:00:00 2001 From: Ashwin Banwari <ashwinkbanw...@gmail.com> Date: Mon, 30 Jun 2025 20:45:39 -0700 Subject: [PATCH] Implement P3618R0 --- clang/docs/ReleaseNotes.rst | 2 ++ clang/include/clang/Basic/DiagnosticSemaKinds.td | 2 +- clang/lib/Sema/SemaDecl.cpp | 9 +++------ clang/test/SemaCXX/modules.cppm | 2 ++ libcxx/utils/libcxx/test/features.py | 2 +- 5 files changed, 9 insertions(+), 8 deletions(-) diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst index e6c8f9df22170..33dd07179aeea 100644 --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -135,6 +135,8 @@ C++2c Feature Support - Implemented `P2719R4 Type-aware allocation and deallocation functions <https://wg21.link/P2719>`_. +- Implemented `P3618R0 Allow attaching main to the global module<https://wg21.link/P3618>`_. + C++23 Feature Support ^^^^^^^^^^^^^^^^^^^^^ diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td b/clang/include/clang/Basic/DiagnosticSemaKinds.td index 5062505cf3c01..d5d982d20eaa5 100644 --- a/clang/include/clang/Basic/DiagnosticSemaKinds.td +++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td @@ -1086,7 +1086,7 @@ def ext_main_used : Extension< "referring to 'main' within an expression is a Clang extension">, InGroup<Main>; def ext_main_invalid_linkage_specification : ExtWarn< "'main' should not be " - "'extern \"%select{C|C++}0\"'">, InGroup<Main>; + "'extern \"C\"'">, InGroup<Main>; /// parser diagnostics def ext_no_declarators : ExtWarn<"declaration does not declare anything">, diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp index a34e2c9cbb003..61b82b8377e22 100644 --- a/clang/lib/Sema/SemaDecl.cpp +++ b/clang/lib/Sema/SemaDecl.cpp @@ -12400,12 +12400,9 @@ bool Sema::CheckFunctionDeclaration(Scope *S, FunctionDecl *NewFD, void Sema::CheckMain(FunctionDecl *FD, const DeclSpec &DS) { // [basic.start.main]p3 - // The main function shall not be declared with a linkage-specification. - if (FD->isExternCContext() || - (FD->isExternCXXContext() && - FD->getDeclContext()->getRedeclContext()->isTranslationUnit())) - Diag(FD->getLocation(), diag::ext_main_invalid_linkage_specification) - << FD->getLanguageLinkage(); + // The main function shall not be declared with C linkage-specification. + if (FD->isExternCContext()) + Diag(FD->getLocation(), diag::ext_main_invalid_linkage_specification); // C++11 [basic.start.main]p3: // A program that [...] declares main to be inline, static or diff --git a/clang/test/SemaCXX/modules.cppm b/clang/test/SemaCXX/modules.cppm index 5d0d6da44a2ed..ddbbc7cd86360 100644 --- a/clang/test/SemaCXX/modules.cppm +++ b/clang/test/SemaCXX/modules.cppm @@ -68,6 +68,8 @@ int n; //--- test3.cpp export module bar; +extern "C++" int main() {} + static int m; int n; diff --git a/libcxx/utils/libcxx/test/features.py b/libcxx/utils/libcxx/test/features.py index 74746e37d3bc4..a479ea48ac810 100644 --- a/libcxx/utils/libcxx/test/features.py +++ b/libcxx/utils/libcxx/test/features.py @@ -340,7 +340,7 @@ def _mingwSupportsModules(cfg): cfg, """ export module test; - int main(int, char**) { return 0; } + extern "C++" int main(int, char**) { return 0; } """, ), ), _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits