Skip to content

[clang] Add test for CWG2811 "Clarify "use" of main" #96168

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jun 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion clang/include/clang/Basic/DiagnosticSemaKinds.td
Original file line number Diff line number Diff line change
Expand Up @@ -964,7 +964,7 @@ def err_main_global_variable :
def warn_main_redefined : Warning<"variable named 'main' with external linkage "
"has undefined behavior">, InGroup<Main>;
def ext_main_used : Extension<
"ISO C++ does not allow 'main' to be used by a program">, InGroup<Main>;
"referring to 'main' within an expression is a Clang extension">, InGroup<Main>;

/// parser diagnostics
def ext_no_declarators : ExtWarn<"declaration does not declare anything">,
Expand Down
4 changes: 2 additions & 2 deletions clang/test/CXX/basic/basic.start/basic.start.init/p3.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ int main(int argc, char **argv)
= delete; // expected-error {{'main' is not allowed to be deleted}}
#else
{
int (*pmain)(int, char**) = &main; // expected-error {{ISO C++ does not allow 'main' to be used by a program}}
int (*pmain)(int, char**) = &main; // expected-error {{referring to 'main' within an expression is a Clang extension}}

if (argc)
main(0, 0); // expected-error {{ISO C++ does not allow 'main' to be used by a program}}
main(0, 0); // expected-error {{referring to 'main' within an expression is a Clang extension}}
}
#endif
24 changes: 24 additions & 0 deletions clang/test/CXX/drs/cwg28xx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,30 @@
// RUN: %clang_cc1 -std=c++23 -pedantic-errors -verify=expected,since-cxx20,since-cxx23 %s
// RUN: %clang_cc1 -std=c++2c -pedantic-errors -verify=expected,since-cxx20,since-cxx23,since-cxx26 %s


int main() {} // required for cwg2811

namespace cwg2811 { // cwg2811: 3.5
#if __cplusplus >= 201103L
void f() {
(void)[&] {
using T = decltype(main);
// expected-error@-1 {{referring to 'main' within an expression is a Clang extension}}
};
using T2 = decltype(main);
// expected-error@-1 {{referring to 'main' within an expression is a Clang extension}}
}

using T = decltype(main);
// expected-error@-1 {{referring to 'main' within an expression is a Clang extension}}

int main();

using U = decltype(main);
using U2 = decltype(&main);
#endif
} // namespace cwg2811

namespace cwg2819 { // cwg2819: 19 tentatively ready 2023-12-01
#if __cpp_constexpr >= 202306L
constexpr void* p = nullptr;
Expand Down
2 changes: 1 addition & 1 deletion clang/www/cxx_dr_status.html
Original file line number Diff line number Diff line change
Expand Up @@ -16675,7 +16675,7 @@ <h2 id="cxxdr">C++ defect report implementation status</h2>
<td><a href="https://cplusplus.github.io/CWG/issues/2811.html">2811</a></td>
<td>DR</td>
<td>Clarify "use" of main</td>
<td class="unknown" align="center">Unknown</td>
<td class="full" align="center">Clang 3.5</td>
</tr>
<tr class="open" id="2812">
<td><a href="https://cplusplus.github.io/CWG/issues/2812.html">2812</a></td>
Expand Down
Loading