Skip to content

Commit 845f998

Browse files
committed
Implement P3618R0
1 parent 66cc167 commit 845f998

File tree

5 files changed

+9
-8
lines changed

5 files changed

+9
-8
lines changed

clang/docs/ReleaseNotes.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,8 @@ C++2c Feature Support
135135

136136
- Implemented `P2719R4 Type-aware allocation and deallocation functions <https://wg21.link/P2719>`_.
137137

138+
- Implemented `P3618R0 Allow attaching main to the global module<https://wg21.link/P3618>`_.
139+
138140
C++23 Feature Support
139141
^^^^^^^^^^^^^^^^^^^^^
140142

clang/include/clang/Basic/DiagnosticSemaKinds.td

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1086,7 +1086,7 @@ def ext_main_used : Extension<
10861086
"referring to 'main' within an expression is a Clang extension">, InGroup<Main>;
10871087
def ext_main_invalid_linkage_specification : ExtWarn<
10881088
"'main' should not be "
1089-
"'extern \"%select{C|C++}0\"'">, InGroup<Main>;
1089+
"'extern \"C\"'">, InGroup<Main>;
10901090

10911091
/// parser diagnostics
10921092
def ext_no_declarators : ExtWarn<"declaration does not declare anything">,

clang/lib/Sema/SemaDecl.cpp

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12400,12 +12400,9 @@ bool Sema::CheckFunctionDeclaration(Scope *S, FunctionDecl *NewFD,
1240012400

1240112401
void Sema::CheckMain(FunctionDecl *FD, const DeclSpec &DS) {
1240212402
// [basic.start.main]p3
12403-
// The main function shall not be declared with a linkage-specification.
12404-
if (FD->isExternCContext() ||
12405-
(FD->isExternCXXContext() &&
12406-
FD->getDeclContext()->getRedeclContext()->isTranslationUnit()))
12407-
Diag(FD->getLocation(), diag::ext_main_invalid_linkage_specification)
12408-
<< FD->getLanguageLinkage();
12403+
// The main function shall not be declared with C linkage-specification.
12404+
if (FD->isExternCContext())
12405+
Diag(FD->getLocation(), diag::ext_main_invalid_linkage_specification);
1240912406

1241012407
// C++11 [basic.start.main]p3:
1241112408
// A program that [...] declares main to be inline, static or

clang/test/SemaCXX/modules.cppm

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,8 @@ int n;
6868
//--- test3.cpp
6969
export module bar;
7070

71+
extern "C++" int main() {}
72+
7173
static int m;
7274

7375
int n;

libcxx/utils/libcxx/test/features.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -340,7 +340,7 @@ def _mingwSupportsModules(cfg):
340340
cfg,
341341
"""
342342
export module test;
343-
int main(int, char**) { return 0; }
343+
extern "C++" int main(int, char**) { return 0; }
344344
""",
345345
),
346346
),

0 commit comments

Comments
 (0)