Files
clang-p2996/clang/test/CXX/basic/basic.start/basic.start.init/p3.cpp
Vlad Serebrennikov 2b5d1fb889 [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".
2024-06-21 13:50:03 +04:00

25 lines
918 B
C++

// RUN: %clang_cc1 -verify %s -pedantic-errors
// RUN: %clang_cc1 -verify %s -pedantic-errors -DINLINE
// RUN: %clang_cc1 -verify %s -pedantic-errors -DSTATIC
// RUN: %clang_cc1 -verify %s -pedantic-errors -std=c++11 -DCONSTEXPR
// RUN: %clang_cc1 -verify %s -std=c++11 -DDELETED
#if INLINE
inline // expected-error {{'main' is not allowed to be declared inline}}
#elif STATIC
static // expected-error {{'main' is not allowed to be declared static}}
#elif CONSTEXPR
constexpr // expected-error {{'main' is not allowed to be declared constexpr}}
#endif
int main(int argc, char **argv)
#if DELETED
= delete; // expected-error {{'main' is not allowed to be deleted}}
#else
{
int (*pmain)(int, char**) = &main; // expected-error {{referring to 'main' within an expression is a Clang extension}}
if (argc)
main(0, 0); // expected-error {{referring to 'main' within an expression is a Clang extension}}
}
#endif