|
| 1 | +// RUN: %clang_cc1 -verify -std=c2y -DSTD1 %s |
| 2 | +// RUN: %clang_cc1 -verify -std=c2y -DSTD2 %s |
| 3 | +// RUN: %clang_cc1 -verify=gnu1 -std=gnu2y -DGNU1 %s |
| 4 | +// RUN: %clang_cc1 -verify -std=gnu2y -DGNU2 %s |
| 5 | +// RUN: %clang_cc1 -verify=gnu3 -std=gnu2y -DGNU3 %s |
| 6 | +// RUN: %clang_cc1 -verify -std=gnu2y -DGNU4 %s |
| 7 | +// RUN: %clang_cc1 -verify -std=gnu2y -DGNU5 %s |
| 8 | +// RUN: %clang_cc1 -verify -std=gnu2y -DGNU6 %s |
| 9 | +// RUN: %clang_cc1 -verify=gnu7 -std=gnu2y -DGNU7 %s |
| 10 | +// RUN: %clang_cc1 -triple x86_64-apple-darwin12 -verify -std=c2y -DDARWIN1 %s |
| 11 | +// RUN: %clang_cc1 -triple x86_64-pc-win32-mscv -verify -std=c2y -fms-compatibility -DMS1 %s |
| 12 | +// RUN: %clang_cc1 -triple x86_64-pc-win32-mscv -verify -std=c2y -fms-compatibility -DMS2 %s |
| 13 | +// RUN: %clang_cc1 -verify=invalid -std=c2y -DINVALID1 %s |
| 14 | +// RUN: %clang_cc1 -verify=invalid -std=c2y -DINVALID2 %s |
| 15 | +// expected-no-diagnostics |
| 16 | + |
| 17 | +/* WG14 N3623: Yes |
| 18 | + * Earthly Demon XV: Definition of Main |
| 19 | + * |
| 20 | + * This validates that we accept the standard type definitions of main or some |
| 21 | + * other implementation-defined type. |
| 22 | + */ |
| 23 | + |
| 24 | +typedef __WCHAR_TYPE__ wchar_t; |
| 25 | + |
| 26 | +// These are the signatures required by the standard. |
| 27 | +#if defined(STD1) |
| 28 | +int main(void) {} |
| 29 | +#elif defined(STD2) |
| 30 | +int main(int argc, char *argv[]) {} |
| 31 | +#endif |
| 32 | + |
| 33 | +// GNU extensions. |
| 34 | +#if defined(GNU1) |
| 35 | +void main(void) {} /* gnu1-warning {{return type of 'main' is not 'int'}} |
| 36 | + gnu1-note {{change return type to 'int'}} |
| 37 | + */ |
| 38 | +#elif defined(GNU2) |
| 39 | +const int main(void) {} |
| 40 | +#elif defined(GNU3) |
| 41 | +int main(...) {} /* gnu3-warning {{'main' is not allowed to be declared variadic}} */ |
| 42 | +#elif defined(GNU4) |
| 43 | +int main(int, const char **) {} |
| 44 | +#elif defined(GNU5) |
| 45 | +int main(int, char const * const *) {} |
| 46 | +#elif defined(GNU6) |
| 47 | +int main(int, char * const *) {} |
| 48 | +#elif defined(GNU7) |
| 49 | +int main(int) {} /* gnu7-warning {{only one parameter on 'main' declaration}} */ |
| 50 | +#endif |
| 51 | + |
| 52 | +// Darwin extensions. |
| 53 | +#if defined(DARWIN1) |
| 54 | +int main(int argc, char *argv[], char *environ[], char **undocumented) {} |
| 55 | +#endif |
| 56 | + |
| 57 | +// Microsoft extensions. |
| 58 | +#if defined(MS1) |
| 59 | +int wmain(int, wchar_t *[]) {} |
| 60 | +#elif defined(MS2) |
| 61 | +int wmain(int, wchar_t *[], wchar_t *[]) {} |
| 62 | +#endif |
| 63 | + |
| 64 | +// Invalid signatures. |
| 65 | +#if defined(INVALID1) |
| 66 | +inline int main(int, char *[]); /* invalid-error {{'main' is not allowed to be declared inline}} */ |
| 67 | +int main(int, char *[], char *[], float); /* invalid-error {{too many parameters (4) for 'main': must be 0, 2, or 3}} */ |
| 68 | +float main(int); /* invalid-error {{'main' must return 'int'}} */ |
| 69 | +_Noreturn int main(int, char *[]); /* invalid-warning {{'main' is not allowed to be declared _Noreturn}} |
| 70 | + invalid-note {{remove '_Noreturn'}} |
| 71 | + */ |
| 72 | +#elif defined(INVALID2) |
| 73 | +static int main(void); /* invalid-warning {{'main' should not be declared static}} */ |
| 74 | +#endif |
0 commit comments