[clang] [clang] Add test for CWG2811 "Clarify "use" of main" (PR #96168)
https://github.com/Endilll closed https://github.com/llvm/llvm-project/pull/96168 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang] Add test for CWG2811 "Clarify "use" of main" (PR #96168)
https://github.com/Endilll updated https://github.com/llvm/llvm-project/pull/96168 >From 7ac89c2758965fec2dd007954735e59d793d6a59 Mon Sep 17 00:00:00 2001 From: Vlad Serebrennikov Date: Thu, 20 Jun 2024 14:07:37 +0300 Subject: [PATCH 1/4] [clang] Add test for CWG2811 "Clarify "use" of main" --- .../clang/Basic/DiagnosticSemaKinds.td| 2 +- .../basic/basic.start/basic.start.init/p3.cpp | 4 ++-- clang/test/CXX/drs/cwg28xx.cpp| 19 +++ clang/www/cxx_dr_status.html | 2 +- 4 files changed, 23 insertions(+), 4 deletions(-) diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td b/clang/include/clang/Basic/DiagnosticSemaKinds.td index 14736784cff5f..b747d2637bd5f 100644 --- a/clang/include/clang/Basic/DiagnosticSemaKinds.td +++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td @@ -964,7 +964,7 @@ def err_main_global_variable : def warn_main_redefined : Warning<"variable named 'main' with external linkage " "has undefined behavior">, InGroup; def ext_main_used : Extension< - "ISO C++ does not allow 'main' to be used by a program">, InGroup; + "expressions that refer to 'main' are an extension">, InGroup; /// parser diagnostics def ext_no_declarators : ExtWarn<"declaration does not declare anything">, diff --git a/clang/test/CXX/basic/basic.start/basic.start.init/p3.cpp b/clang/test/CXX/basic/basic.start/basic.start.init/p3.cpp index 506232ebacc4c..8f215172235c2 100644 --- a/clang/test/CXX/basic/basic.start/basic.start.init/p3.cpp +++ b/clang/test/CXX/basic/basic.start/basic.start.init/p3.cpp @@ -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**) = // expected-error {{ISO C++ does not allow 'main' to be used by a program}} + int (*pmain)(int, char**) = // expected-error {{expressions that refer to 'main' are an 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 {{expressions that refer to 'main' are an extension}} } #endif diff --git a/clang/test/CXX/drs/cwg28xx.cpp b/clang/test/CXX/drs/cwg28xx.cpp index da81eccc8dc22..049d90a1f7b20 100644 --- a/clang/test/CXX/drs/cwg28xx.cpp +++ b/clang/test/CXX/drs/cwg28xx.cpp @@ -6,6 +6,25 @@ // 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 {{expressions that refer to 'main' are an extension}} + }; + using T2 = decltype(main); + // expected-error@-1 {{expressions that refer to 'main' are an extension}} +} + +using T = decltype(main); +// expected-error@-1 {{expressions that refer to 'main' are an extension}} +#endif +} // namespace cwg2811 + namespace cwg2819 { // cwg2819: 19 tentatively ready 2023-12-01 #if __cpp_constexpr >= 202306L constexpr void* p = nullptr; diff --git a/clang/www/cxx_dr_status.html b/clang/www/cxx_dr_status.html index dac38cedfcb75..d6b7c32dd844d 100755 --- a/clang/www/cxx_dr_status.html +++ b/clang/www/cxx_dr_status.html @@ -16675,7 +16675,7 @@ C++ defect report implementation status https://cplusplus.github.io/CWG/issues/2811.html;>2811 DR Clarify "use" of main -Unknown +Clang 3.5 https://cplusplus.github.io/CWG/issues/2812.html;>2812 >From 7043728a9b59ce6fb741f83adec0ae866b8d78fa Mon Sep 17 00:00:00 2001 From: Vlad Serebrennikov Date: Thu, 20 Jun 2024 15:56:21 +0300 Subject: [PATCH 2/4] Add tests for a `main` function inside a namespace --- clang/test/CXX/drs/cwg28xx.cpp | 5 + 1 file changed, 5 insertions(+) diff --git a/clang/test/CXX/drs/cwg28xx.cpp b/clang/test/CXX/drs/cwg28xx.cpp index 049d90a1f7b20..66ffbdf5e0d2b 100644 --- a/clang/test/CXX/drs/cwg28xx.cpp +++ b/clang/test/CXX/drs/cwg28xx.cpp @@ -22,6 +22,11 @@ void f() { using T = decltype(main); // expected-error@-1 {{expressions that refer to 'main' are an extension}} + +int main(); + +using U = decltype(main); +using U2 = decltype(); #endif } // namespace cwg2811 >From f3bcd9da2fa99fb6bab913adb9139e76145b46a2 Mon Sep 17 00:00:00 2001 From: Vlad Serebrennikov Date: Thu, 20 Jun 2024 16:46:02 +0300 Subject: [PATCH 3/4] Clarify that it's a Clang extension as @AaronBallman suggested --- clang/include/clang/Basic/DiagnosticSemaKinds.td | 2 +- clang/test/CXX/basic/basic.start/basic.start.init/p3.cpp | 4 ++-- clang/test/CXX/drs/cwg28xx.cpp | 6 +++--- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td b/clang/include/clang/Basic/DiagnosticSemaKinds.td index b747d2637bd5f..8cdc05f360003 100644 ---
[clang] [clang] Add test for CWG2811 "Clarify "use" of main" (PR #96168)
@@ -964,7 +964,7 @@ def err_main_global_variable : def warn_main_redefined : Warning<"variable named 'main' with external linkage " "has undefined behavior">, InGroup; def ext_main_used : Extension< - "ISO C++ does not allow 'main' to be used by a program">, InGroup; + "expressions that refer to 'main' are an extension">, InGroup; AaronBallman wrote: Good point about `decltype` accepting an expression. This is fine by me. https://github.com/llvm/llvm-project/pull/96168 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang] Add test for CWG2811 "Clarify "use" of main" (PR #96168)
https://github.com/AaronBallman approved this pull request. LGTM! https://github.com/llvm/llvm-project/pull/96168 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang] Add test for CWG2811 "Clarify "use" of main" (PR #96168)
https://github.com/cor3ntin approved this pull request. LGTM if @AaronBallman is happy ("expressions that... are an extensions" still sounds weird to me, cf previous comment) https://github.com/llvm/llvm-project/pull/96168 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang] Add test for CWG2811 "Clarify "use" of main" (PR #96168)
Endilll wrote: > do we have test that this is fine? > > ``` > namespace foo { > int main(); > using a = decltype(); > }``` > ``` Thank you, I added the tests. https://github.com/llvm/llvm-project/pull/96168 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang] Add test for CWG2811 "Clarify "use" of main" (PR #96168)
@@ -964,7 +964,7 @@ def err_main_global_variable : def warn_main_redefined : Warning<"variable named 'main' with external linkage " "has undefined behavior">, InGroup; def ext_main_used : Extension< - "ISO C++ does not allow 'main' to be used by a program">, InGroup; + "expressions that refer to 'main' are an extension">, InGroup; Endilll wrote: I applied the suggestion. https://github.com/llvm/llvm-project/pull/96168 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang] Add test for CWG2811 "Clarify "use" of main" (PR #96168)
https://github.com/Endilll updated https://github.com/llvm/llvm-project/pull/96168 >From 7ac89c2758965fec2dd007954735e59d793d6a59 Mon Sep 17 00:00:00 2001 From: Vlad Serebrennikov Date: Thu, 20 Jun 2024 14:07:37 +0300 Subject: [PATCH 1/3] [clang] Add test for CWG2811 "Clarify "use" of main" --- .../clang/Basic/DiagnosticSemaKinds.td| 2 +- .../basic/basic.start/basic.start.init/p3.cpp | 4 ++-- clang/test/CXX/drs/cwg28xx.cpp| 19 +++ clang/www/cxx_dr_status.html | 2 +- 4 files changed, 23 insertions(+), 4 deletions(-) diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td b/clang/include/clang/Basic/DiagnosticSemaKinds.td index 14736784cff5f..b747d2637bd5f 100644 --- a/clang/include/clang/Basic/DiagnosticSemaKinds.td +++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td @@ -964,7 +964,7 @@ def err_main_global_variable : def warn_main_redefined : Warning<"variable named 'main' with external linkage " "has undefined behavior">, InGroup; def ext_main_used : Extension< - "ISO C++ does not allow 'main' to be used by a program">, InGroup; + "expressions that refer to 'main' are an extension">, InGroup; /// parser diagnostics def ext_no_declarators : ExtWarn<"declaration does not declare anything">, diff --git a/clang/test/CXX/basic/basic.start/basic.start.init/p3.cpp b/clang/test/CXX/basic/basic.start/basic.start.init/p3.cpp index 506232ebacc4c..8f215172235c2 100644 --- a/clang/test/CXX/basic/basic.start/basic.start.init/p3.cpp +++ b/clang/test/CXX/basic/basic.start/basic.start.init/p3.cpp @@ -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**) = // expected-error {{ISO C++ does not allow 'main' to be used by a program}} + int (*pmain)(int, char**) = // expected-error {{expressions that refer to 'main' are an 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 {{expressions that refer to 'main' are an extension}} } #endif diff --git a/clang/test/CXX/drs/cwg28xx.cpp b/clang/test/CXX/drs/cwg28xx.cpp index da81eccc8dc22..049d90a1f7b20 100644 --- a/clang/test/CXX/drs/cwg28xx.cpp +++ b/clang/test/CXX/drs/cwg28xx.cpp @@ -6,6 +6,25 @@ // 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 {{expressions that refer to 'main' are an extension}} + }; + using T2 = decltype(main); + // expected-error@-1 {{expressions that refer to 'main' are an extension}} +} + +using T = decltype(main); +// expected-error@-1 {{expressions that refer to 'main' are an extension}} +#endif +} // namespace cwg2811 + namespace cwg2819 { // cwg2819: 19 tentatively ready 2023-12-01 #if __cpp_constexpr >= 202306L constexpr void* p = nullptr; diff --git a/clang/www/cxx_dr_status.html b/clang/www/cxx_dr_status.html index dac38cedfcb75..d6b7c32dd844d 100755 --- a/clang/www/cxx_dr_status.html +++ b/clang/www/cxx_dr_status.html @@ -16675,7 +16675,7 @@ C++ defect report implementation status https://cplusplus.github.io/CWG/issues/2811.html;>2811 DR Clarify "use" of main -Unknown +Clang 3.5 https://cplusplus.github.io/CWG/issues/2812.html;>2812 >From 7043728a9b59ce6fb741f83adec0ae866b8d78fa Mon Sep 17 00:00:00 2001 From: Vlad Serebrennikov Date: Thu, 20 Jun 2024 15:56:21 +0300 Subject: [PATCH 2/3] Add tests for a `main` function inside a namespace --- clang/test/CXX/drs/cwg28xx.cpp | 5 + 1 file changed, 5 insertions(+) diff --git a/clang/test/CXX/drs/cwg28xx.cpp b/clang/test/CXX/drs/cwg28xx.cpp index 049d90a1f7b20..66ffbdf5e0d2b 100644 --- a/clang/test/CXX/drs/cwg28xx.cpp +++ b/clang/test/CXX/drs/cwg28xx.cpp @@ -22,6 +22,11 @@ void f() { using T = decltype(main); // expected-error@-1 {{expressions that refer to 'main' are an extension}} + +int main(); + +using U = decltype(main); +using U2 = decltype(); #endif } // namespace cwg2811 >From f3bcd9da2fa99fb6bab913adb9139e76145b46a2 Mon Sep 17 00:00:00 2001 From: Vlad Serebrennikov Date: Thu, 20 Jun 2024 16:46:02 +0300 Subject: [PATCH 3/3] Clarify that it's a Clang extension as @AaronBallman suggested --- clang/include/clang/Basic/DiagnosticSemaKinds.td | 2 +- clang/test/CXX/basic/basic.start/basic.start.init/p3.cpp | 4 ++-- clang/test/CXX/drs/cwg28xx.cpp | 6 +++--- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td b/clang/include/clang/Basic/DiagnosticSemaKinds.td index b747d2637bd5f..8cdc05f360003 100644 ---
[clang] [clang] Add test for CWG2811 "Clarify "use" of main" (PR #96168)
https://github.com/Endilll updated https://github.com/llvm/llvm-project/pull/96168 >From 7ac89c2758965fec2dd007954735e59d793d6a59 Mon Sep 17 00:00:00 2001 From: Vlad Serebrennikov Date: Thu, 20 Jun 2024 14:07:37 +0300 Subject: [PATCH 1/2] [clang] Add test for CWG2811 "Clarify "use" of main" --- .../clang/Basic/DiagnosticSemaKinds.td| 2 +- .../basic/basic.start/basic.start.init/p3.cpp | 4 ++-- clang/test/CXX/drs/cwg28xx.cpp| 19 +++ clang/www/cxx_dr_status.html | 2 +- 4 files changed, 23 insertions(+), 4 deletions(-) diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td b/clang/include/clang/Basic/DiagnosticSemaKinds.td index 14736784cff5f..b747d2637bd5f 100644 --- a/clang/include/clang/Basic/DiagnosticSemaKinds.td +++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td @@ -964,7 +964,7 @@ def err_main_global_variable : def warn_main_redefined : Warning<"variable named 'main' with external linkage " "has undefined behavior">, InGroup; def ext_main_used : Extension< - "ISO C++ does not allow 'main' to be used by a program">, InGroup; + "expressions that refer to 'main' are an extension">, InGroup; /// parser diagnostics def ext_no_declarators : ExtWarn<"declaration does not declare anything">, diff --git a/clang/test/CXX/basic/basic.start/basic.start.init/p3.cpp b/clang/test/CXX/basic/basic.start/basic.start.init/p3.cpp index 506232ebacc4c..8f215172235c2 100644 --- a/clang/test/CXX/basic/basic.start/basic.start.init/p3.cpp +++ b/clang/test/CXX/basic/basic.start/basic.start.init/p3.cpp @@ -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**) = // expected-error {{ISO C++ does not allow 'main' to be used by a program}} + int (*pmain)(int, char**) = // expected-error {{expressions that refer to 'main' are an 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 {{expressions that refer to 'main' are an extension}} } #endif diff --git a/clang/test/CXX/drs/cwg28xx.cpp b/clang/test/CXX/drs/cwg28xx.cpp index da81eccc8dc22..049d90a1f7b20 100644 --- a/clang/test/CXX/drs/cwg28xx.cpp +++ b/clang/test/CXX/drs/cwg28xx.cpp @@ -6,6 +6,25 @@ // 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 {{expressions that refer to 'main' are an extension}} + }; + using T2 = decltype(main); + // expected-error@-1 {{expressions that refer to 'main' are an extension}} +} + +using T = decltype(main); +// expected-error@-1 {{expressions that refer to 'main' are an extension}} +#endif +} // namespace cwg2811 + namespace cwg2819 { // cwg2819: 19 tentatively ready 2023-12-01 #if __cpp_constexpr >= 202306L constexpr void* p = nullptr; diff --git a/clang/www/cxx_dr_status.html b/clang/www/cxx_dr_status.html index dac38cedfcb75..d6b7c32dd844d 100755 --- a/clang/www/cxx_dr_status.html +++ b/clang/www/cxx_dr_status.html @@ -16675,7 +16675,7 @@ C++ defect report implementation status https://cplusplus.github.io/CWG/issues/2811.html;>2811 DR Clarify "use" of main -Unknown +Clang 3.5 https://cplusplus.github.io/CWG/issues/2812.html;>2812 >From 7043728a9b59ce6fb741f83adec0ae866b8d78fa Mon Sep 17 00:00:00 2001 From: Vlad Serebrennikov Date: Thu, 20 Jun 2024 15:56:21 +0300 Subject: [PATCH 2/2] Add tests for a `main` function inside a namespace --- clang/test/CXX/drs/cwg28xx.cpp | 5 + 1 file changed, 5 insertions(+) diff --git a/clang/test/CXX/drs/cwg28xx.cpp b/clang/test/CXX/drs/cwg28xx.cpp index 049d90a1f7b20..66ffbdf5e0d2b 100644 --- a/clang/test/CXX/drs/cwg28xx.cpp +++ b/clang/test/CXX/drs/cwg28xx.cpp @@ -22,6 +22,11 @@ void f() { using T = decltype(main); // expected-error@-1 {{expressions that refer to 'main' are an extension}} + +int main(); + +using U = decltype(main); +using U2 = decltype(); #endif } // namespace cwg2811 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang] Add test for CWG2811 "Clarify "use" of main" (PR #96168)
@@ -964,7 +964,7 @@ def err_main_global_variable : def warn_main_redefined : Warning<"variable named 'main' with external linkage " "has undefined behavior">, InGroup; def ext_main_used : Extension< - "ISO C++ does not allow 'main' to be used by a program">, InGroup; + "expressions that refer to 'main' are an extension">, InGroup; cor3ntin wrote: no, it's not. `main` is named by an expression (which is unevaluated) https://github.com/llvm/llvm-project/pull/96168 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang] Add test for CWG2811 "Clarify "use" of main" (PR #96168)
@@ -964,7 +964,7 @@ def err_main_global_variable : def warn_main_redefined : Warning<"variable named 'main' with external linkage " "has undefined behavior">, InGroup; def ext_main_used : Extension< - "ISO C++ does not allow 'main' to be used by a program">, InGroup; + "expressions that refer to 'main' are an extension">, InGroup; AaronBallman wrote: ```suggestion "expressions that refer to 'main' are a Clang extension">, InGroup; ``` I think there's work to be done for full conformance here though. For example, this DR clarified that the following code is valid, but we still diagnose it as an extension: ``` int main() {} decltype(main) maine; ``` https://godbolt.org/z/nn8rd483Y https://github.com/llvm/llvm-project/pull/96168 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang] Add test for CWG2811 "Clarify "use" of main" (PR #96168)
Endilll wrote: > it's clearer that it's not conforming (at the very least we should say > something like "clang extension" As someone who was a user of Clang not so long ago, I have to say that the only thing "ISO C++ requires" conveyed to me was "you're doing something wrong". For me it never had a clear interpretation "you're asking for an extension, but we're not giving it to you". On the other hand, I believe the word "extension" is clearly understood to describe something outside of ISO C++, somewhat by definition. At least that would match my understanding 3-4 years ago. CC @AaronBallman I remember we discussed it offline a while ago. https://github.com/llvm/llvm-project/pull/96168 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang] Add test for CWG2811 "Clarify "use" of main" (PR #96168)
cor3ntin wrote: I think I prefer the current wording, it's clearer that it's not conforming (at the very least we should say something like "clang extension". and maybe "referring to main is a clang extension". LGTM otherwise do we have test that this is fine? ``` namespace foo { int main(); using a = decltype(); }``` https://github.com/llvm/llvm-project/pull/96168 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang] Add test for CWG2811 "Clarify "use" of main" (PR #96168)
llvmbot wrote: @llvm/pr-subscribers-clang Author: Vlad Serebrennikov (Endilll) Changes 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". --- Full diff: https://github.com/llvm/llvm-project/pull/96168.diff 4 Files Affected: - (modified) clang/include/clang/Basic/DiagnosticSemaKinds.td (+1-1) - (modified) clang/test/CXX/basic/basic.start/basic.start.init/p3.cpp (+2-2) - (modified) clang/test/CXX/drs/cwg28xx.cpp (+19) - (modified) clang/www/cxx_dr_status.html (+1-1) ``diff diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td b/clang/include/clang/Basic/DiagnosticSemaKinds.td index 14736784cff5f..b747d2637bd5f 100644 --- a/clang/include/clang/Basic/DiagnosticSemaKinds.td +++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td @@ -964,7 +964,7 @@ def err_main_global_variable : def warn_main_redefined : Warning<"variable named 'main' with external linkage " "has undefined behavior">, InGroup; def ext_main_used : Extension< - "ISO C++ does not allow 'main' to be used by a program">, InGroup; + "expressions that refer to 'main' are an extension">, InGroup; /// parser diagnostics def ext_no_declarators : ExtWarn<"declaration does not declare anything">, diff --git a/clang/test/CXX/basic/basic.start/basic.start.init/p3.cpp b/clang/test/CXX/basic/basic.start/basic.start.init/p3.cpp index 506232ebacc4c..8f215172235c2 100644 --- a/clang/test/CXX/basic/basic.start/basic.start.init/p3.cpp +++ b/clang/test/CXX/basic/basic.start/basic.start.init/p3.cpp @@ -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**) = // expected-error {{ISO C++ does not allow 'main' to be used by a program}} + int (*pmain)(int, char**) = // expected-error {{expressions that refer to 'main' are an 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 {{expressions that refer to 'main' are an extension}} } #endif diff --git a/clang/test/CXX/drs/cwg28xx.cpp b/clang/test/CXX/drs/cwg28xx.cpp index da81eccc8dc22..049d90a1f7b20 100644 --- a/clang/test/CXX/drs/cwg28xx.cpp +++ b/clang/test/CXX/drs/cwg28xx.cpp @@ -6,6 +6,25 @@ // 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 {{expressions that refer to 'main' are an extension}} + }; + using T2 = decltype(main); + // expected-error@-1 {{expressions that refer to 'main' are an extension}} +} + +using T = decltype(main); +// expected-error@-1 {{expressions that refer to 'main' are an extension}} +#endif +} // namespace cwg2811 + namespace cwg2819 { // cwg2819: 19 tentatively ready 2023-12-01 #if __cpp_constexpr >= 202306L constexpr void* p = nullptr; diff --git a/clang/www/cxx_dr_status.html b/clang/www/cxx_dr_status.html index dac38cedfcb75..d6b7c32dd844d 100755 --- a/clang/www/cxx_dr_status.html +++ b/clang/www/cxx_dr_status.html @@ -16675,7 +16675,7 @@ C++ defect report implementation status https://cplusplus.github.io/CWG/issues/2811.html;>2811 DR Clarify "use" of main -Unknown +Clang 3.5 https://cplusplus.github.io/CWG/issues/2812.html;>2812 `` https://github.com/llvm/llvm-project/pull/96168 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang] Add test for CWG2811 "Clarify "use" of main" (PR #96168)
https://github.com/Endilll created https://github.com/llvm/llvm-project/pull/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". >From 7ac89c2758965fec2dd007954735e59d793d6a59 Mon Sep 17 00:00:00 2001 From: Vlad Serebrennikov Date: Thu, 20 Jun 2024 14:07:37 +0300 Subject: [PATCH] [clang] Add test for CWG2811 "Clarify "use" of main" --- .../clang/Basic/DiagnosticSemaKinds.td| 2 +- .../basic/basic.start/basic.start.init/p3.cpp | 4 ++-- clang/test/CXX/drs/cwg28xx.cpp| 19 +++ clang/www/cxx_dr_status.html | 2 +- 4 files changed, 23 insertions(+), 4 deletions(-) diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td b/clang/include/clang/Basic/DiagnosticSemaKinds.td index 14736784cff5f..b747d2637bd5f 100644 --- a/clang/include/clang/Basic/DiagnosticSemaKinds.td +++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td @@ -964,7 +964,7 @@ def err_main_global_variable : def warn_main_redefined : Warning<"variable named 'main' with external linkage " "has undefined behavior">, InGroup; def ext_main_used : Extension< - "ISO C++ does not allow 'main' to be used by a program">, InGroup; + "expressions that refer to 'main' are an extension">, InGroup; /// parser diagnostics def ext_no_declarators : ExtWarn<"declaration does not declare anything">, diff --git a/clang/test/CXX/basic/basic.start/basic.start.init/p3.cpp b/clang/test/CXX/basic/basic.start/basic.start.init/p3.cpp index 506232ebacc4c..8f215172235c2 100644 --- a/clang/test/CXX/basic/basic.start/basic.start.init/p3.cpp +++ b/clang/test/CXX/basic/basic.start/basic.start.init/p3.cpp @@ -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**) = // expected-error {{ISO C++ does not allow 'main' to be used by a program}} + int (*pmain)(int, char**) = // expected-error {{expressions that refer to 'main' are an 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 {{expressions that refer to 'main' are an extension}} } #endif diff --git a/clang/test/CXX/drs/cwg28xx.cpp b/clang/test/CXX/drs/cwg28xx.cpp index da81eccc8dc22..049d90a1f7b20 100644 --- a/clang/test/CXX/drs/cwg28xx.cpp +++ b/clang/test/CXX/drs/cwg28xx.cpp @@ -6,6 +6,25 @@ // 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 {{expressions that refer to 'main' are an extension}} + }; + using T2 = decltype(main); + // expected-error@-1 {{expressions that refer to 'main' are an extension}} +} + +using T = decltype(main); +// expected-error@-1 {{expressions that refer to 'main' are an extension}} +#endif +} // namespace cwg2811 + namespace cwg2819 { // cwg2819: 19 tentatively ready 2023-12-01 #if __cpp_constexpr >= 202306L constexpr void* p = nullptr; diff --git a/clang/www/cxx_dr_status.html b/clang/www/cxx_dr_status.html index dac38cedfcb75..d6b7c32dd844d 100755 --- a/clang/www/cxx_dr_status.html +++ b/clang/www/cxx_dr_status.html @@ -16675,7 +16675,7 @@ C++ defect report implementation status https://cplusplus.github.io/CWG/issues/2811.html;>2811 DR Clarify "use" of main -Unknown +Clang 3.5 https://cplusplus.github.io/CWG/issues/2812.html;>2812 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits