Skip to content

Commit 2b5d1fb

Browse files
authored
[clang] Add test for CWG2811 "Clarify "use" of main" (#96168)
This patch covers [CWG2811](https://cplusplus.github.io/CWG/issues/2811.html) "Clarify "use" of main", basically adding a test for `-Wmain`, focusing on usages of `main` in unevaluated contexts. To my understanding, the diagnostic message is based on the wording, so I updated it based on the new wording. I also replaces "ISO C++ requires" with a phrasing that explicitly says "extension".
1 parent bc4d50f commit 2b5d1fb

File tree

4 files changed

+28
-4
lines changed

4 files changed

+28
-4
lines changed

clang/include/clang/Basic/DiagnosticSemaKinds.td

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -973,7 +973,7 @@ def err_main_global_variable :
973973
def warn_main_redefined : Warning<"variable named 'main' with external linkage "
974974
"has undefined behavior">, InGroup<Main>;
975975
def ext_main_used : Extension<
976-
"ISO C++ does not allow 'main' to be used by a program">, InGroup<Main>;
976+
"referring to 'main' within an expression is a Clang extension">, InGroup<Main>;
977977

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

clang/test/CXX/basic/basic.start/basic.start.init/p3.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@ int main(int argc, char **argv)
1616
= delete; // expected-error {{'main' is not allowed to be deleted}}
1717
#else
1818
{
19-
int (*pmain)(int, char**) = &main; // expected-error {{ISO C++ does not allow 'main' to be used by a program}}
19+
int (*pmain)(int, char**) = &main; // expected-error {{referring to 'main' within an expression is a Clang extension}}
2020

2121
if (argc)
22-
main(0, 0); // expected-error {{ISO C++ does not allow 'main' to be used by a program}}
22+
main(0, 0); // expected-error {{referring to 'main' within an expression is a Clang extension}}
2323
}
2424
#endif

clang/test/CXX/drs/cwg28xx.cpp

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,30 @@
66
// RUN: %clang_cc1 -std=c++23 -pedantic-errors -verify=expected,since-cxx20,since-cxx23 %s
77
// RUN: %clang_cc1 -std=c++2c -pedantic-errors -verify=expected,since-cxx20,since-cxx23,since-cxx26 %s
88

9+
10+
int main() {} // required for cwg2811
11+
12+
namespace cwg2811 { // cwg2811: 3.5
13+
#if __cplusplus >= 201103L
14+
void f() {
15+
(void)[&] {
16+
using T = decltype(main);
17+
// expected-error@-1 {{referring to 'main' within an expression is a Clang extension}}
18+
};
19+
using T2 = decltype(main);
20+
// expected-error@-1 {{referring to 'main' within an expression is a Clang extension}}
21+
}
22+
23+
using T = decltype(main);
24+
// expected-error@-1 {{referring to 'main' within an expression is a Clang extension}}
25+
26+
int main();
27+
28+
using U = decltype(main);
29+
using U2 = decltype(&main);
30+
#endif
31+
} // namespace cwg2811
32+
933
namespace cwg2819 { // cwg2819: 19 tentatively ready 2023-12-01
1034
#if __cpp_constexpr >= 202306L
1135
constexpr void* p = nullptr;

clang/www/cxx_dr_status.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16682,7 +16682,7 @@ <h2 id="cxxdr">C++ defect report implementation status</h2>
1668216682
<td><a href="https://cplusplus.github.io/CWG/issues/2811.html">2811</a></td>
1668316683
<td>DR</td>
1668416684
<td>Clarify "use" of main</td>
16685-
<td class="unknown" align="center">Unknown</td>
16685+
<td class="full" align="center">Clang 3.5</td>
1668616686
</tr>
1668716687
<tr class="open" id="2812">
1668816688
<td><a href="https://cplusplus.github.io/CWG/issues/2812.html">2812</a></td>

0 commit comments

Comments
 (0)