| 1 |
// RUN: %clang_cc1 -fsyntax-only -verify %s -DTEST1 |
| 2 |
// RUN: %clang_cc1 -fsyntax-only -verify %s -DTEST2 |
| 3 |
// RUN: %clang_cc1 -fsyntax-only -verify %s -DTEST3 |
| 4 |
// RUN: %clang_cc1 -fsyntax-only -verify %s -DTEST4 |
| 5 |
// RUN: %clang_cc1 -fsyntax-only -verify %s -std=c++14 -DTEST5 |
| 6 |
// RUN: %clang_cc1 -fsyntax-only -verify %s -std=c++14 -DTEST6 |
| 7 |
// RUN: %clang_cc1 -fsyntax-only -verify %s -DTEST7 |
| 8 |
// RUN: %clang_cc1 -fsyntax-only -verify %s -DTEST8 |
| 9 |
// RUN: %clang_cc1 -fsyntax-only -verify %s -DTEST9 |
| 10 |
// RUN: %clang_cc1 -fsyntax-only -verify %s -DTEST10 -ffreestanding |
| 11 |
// RUN: %clang_cc1 -fsyntax-only -verify -pedantic %s -DTEST11 |
| 12 |
// RUN: %clang_cc1 -fsyntax-only -verify -pedantic %s -DTEST12 |
| 13 |
// RUN: %clang_cc1 -fsyntax-only -verify -pedantic %s -DTEST13 |
| 14 |
// RUN: %clang_cc1 -fsyntax-only -verify -pedantic %s -DTEST14 |
| 15 |
// RUN: %clang_cc1 -triple x86_64-linux -emit-llvm-only -verify -pedantic %s -DTEST15 |
| 16 |
|
| 17 |
#if TEST1 |
| 18 |
int main; // expected-error{{main cannot be declared as a variable in the global scope}} |
| 19 |
|
| 20 |
#elif TEST2 |
| 21 |
// expected-no-diagnostics |
| 22 |
int f () { |
| 23 |
int main; |
| 24 |
return main; |
| 25 |
} |
| 26 |
|
| 27 |
#elif TEST3 |
| 28 |
// expected-no-diagnostics |
| 29 |
void x(int main) {}; |
| 30 |
int y(int main); |
| 31 |
|
| 32 |
#elif TEST4 |
| 33 |
// expected-no-diagnostics |
| 34 |
class A { |
| 35 |
static int main; |
| 36 |
}; |
| 37 |
|
| 38 |
#elif TEST5 |
| 39 |
// expected-no-diagnostics |
| 40 |
template<class T> constexpr T main; |
| 41 |
|
| 42 |
#elif TEST6 |
| 43 |
extern template<class T> constexpr T main; //expected-error{{expected unqualified-id}} |
| 44 |
|
| 45 |
#elif TEST7 |
| 46 |
// expected-no-diagnostics |
| 47 |
namespace foo { |
| 48 |
int main; |
| 49 |
} |
| 50 |
|
| 51 |
#elif TEST8 |
| 52 |
void z(void) |
| 53 |
{ |
| 54 |
extern int main; // expected-error{{main cannot be declared as a variable in the global scope}}} |
| 55 |
} |
| 56 |
|
| 57 |
#elif TEST9 |
| 58 |
// expected-no-diagnostics |
| 59 |
int q(void) |
| 60 |
{ |
| 61 |
static int main; |
| 62 |
return main; |
| 63 |
} |
| 64 |
|
| 65 |
#elif TEST10 |
| 66 |
// expected-no-diagnostics |
| 67 |
int main; |
| 68 |
|
| 69 |
#elif TEST11 |
| 70 |
extern "C" { |
| 71 |
namespace Y { |
| 72 |
int main; // expected-error {{main cannot be declared as a variable with C language linkage}}} |
| 73 |
} |
| 74 |
} |
| 75 |
namespace ns { |
| 76 |
extern "C" int main; // expected-error {{main cannot be declared as a variable with C language linkage}} |
| 77 |
} |
| 78 |
|
| 79 |
#elif TEST12 |
| 80 |
extern "C" struct A { int main(); }; // ok |
| 81 |
|
| 82 |
namespace c { |
| 83 |
extern "C" void main(); // expected-error {{'main' must return 'int'}} \ |
| 84 |
// expected-warning {{'main' should not be 'extern "C"'}} |
| 85 |
} |
| 86 |
|
| 87 |
extern "C" { |
| 88 |
namespace Z { |
| 89 |
void main(); // expected-error {{'main' must return 'int'}} \ |
| 90 |
// expected-warning {{'main' should not be 'extern "C"'}} |
| 91 |
} |
| 92 |
} |
| 93 |
|
| 94 |
namespace ns { |
| 95 |
extern "C" struct A { |
| 96 |
int main; // ok |
| 97 |
}; |
| 98 |
|
| 99 |
extern "C" struct B { |
| 100 |
int main(); // ok |
| 101 |
}; |
| 102 |
} |
| 103 |
|
| 104 |
#elif TEST13 |
| 105 |
// expected-no-diagnostics |
| 106 |
extern "C++" { |
| 107 |
int main(); |
| 108 |
} |
| 109 |
|
| 110 |
extern "C++" int main(); |
| 111 |
|
| 112 |
namespace ns1 { |
| 113 |
extern "C++" int main(); // ok |
| 114 |
extern "C" { |
| 115 |
extern "C++" { |
| 116 |
int main(void *); // ok |
| 117 |
} |
| 118 |
} |
| 119 |
} |
| 120 |
|
| 121 |
namespace ns2 { |
| 122 |
extern "C++" void main() {} // ok |
| 123 |
} |
| 124 |
|
| 125 |
#elif TEST14 |
| 126 |
extern "C" { |
| 127 |
int main(); // expected-warning {{'main' should not be 'extern "C"'}} |
| 128 |
} |
| 129 |
|
| 130 |
extern "C" int main(); // expected-warning {{'main' should not be 'extern "C"'}} |
| 131 |
|
| 132 |
#elif TEST15 |
| 133 |
extern "C" __attribute__((visibility("default"))) __attribute__((weak)) |
| 134 |
int main(); // expected-warning {{'main' should not be 'extern "C"'}} |
| 135 |
|
| 136 |
unsigned long g() { |
| 137 |
return reinterpret_cast<unsigned long>(&main); // expected-warning {{referring to 'main' within an expression is a Clang extension}} |
| 138 |
} |
| 139 |
|
| 140 |
#else |
| 141 |
#error Unknown Test |
| 142 |
#endif |