Skip to content

Commit 4f80c06

Browse files
authored
[runtimes][NFC] Consistently declare main() functions in tests (#162548)
In the libc++ test suite, we consistently declare main() functions with full parameters and explicitly return from the function. This helps code that compiles the tests with -ffreestanding, where main() is not a special function (with an implicit return and special mangling). This patch fixes a few stray declarations, including in libunwind and libc++abi.
1 parent 5841319 commit 4f80c06

14 files changed

+32
-22
lines changed

libcxx/test/std/localization/codecvt_unicode.pass.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2222,10 +2222,11 @@ void test_utf16_ucs2_codecvts() {
22222222
#endif
22232223
}
22242224

2225-
int main() {
2225+
int main(int, char**) {
22262226
test_utf8_utf32_codecvts();
22272227
test_utf8_utf16_codecvts();
22282228
test_utf8_ucs2_codecvts();
22292229
test_utf16_utf32_codecvts();
22302230
test_utf16_ucs2_codecvts();
2231+
return 0;
22312232
}

libcxx/test/std/ranges/range.access/include.iterator.pass.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,8 @@ constexpr bool test() {
6262
return true;
6363
}
6464

65-
int main() {
65+
int main(int, char**) {
6666
test();
6767
static_assert(test());
68+
return 0;
6869
}

libcxx/utils/libcxx/test/dsl.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -296,7 +296,7 @@ def hasAnyLocale(config, locales):
296296
+ name_string_literals
297297
+ """, nullptr,
298298
};
299-
int main() {
299+
int main(int, char**) {
300300
for (size_t i = 0; test_locale_names[i]; i++) {
301301
if (::setlocale(LC_ALL, test_locale_names[i]) != NULL) {
302302
return 0;

libcxx/utils/libcxx/test/features.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ def _getAndroidDeviceApi(cfg):
3030
r"""
3131
#include <android/api-level.h>
3232
#include <stdio.h>
33-
int main() {
33+
int main(int, char**) {
3434
printf("%d\n", android_get_device_api_level());
3535
return 0;
3636
}
@@ -66,7 +66,7 @@ def _mingwSupportsModules(cfg):
6666
#else
6767
// __MINGW64_VERSION_MAJOR > 12 should be ok.
6868
#endif
69-
int main() { return 0; }
69+
int main(int, char**) { return 0; }
7070
""",
7171
)
7272

@@ -474,7 +474,7 @@ def _getLocaleFlagsAction(cfg, locale, alts, members):
474474
#include <wchar.h>
475475
476476
// Print each requested locale conversion member on separate lines.
477-
int main() {
477+
int main(int, char**) {
478478
const char* locales[] = { %s };
479479
for (int loc_i = 0; loc_i < %d; ++loc_i) {
480480
if (!setlocale(LC_ALL, locales[loc_i])) {
@@ -629,7 +629,7 @@ def _getLocaleFlagsAction(cfg, locale, alts, members):
629629
"""
630630
#include <stdio.h>
631631
#include <windows.h>
632-
int main() {
632+
int main(int, char**) {
633633
CHAR tempDirPath[MAX_PATH];
634634
DWORD tempPathRet = GetTempPathA(MAX_PATH, tempDirPath);
635635
if (tempPathRet == 0 || tempPathRet > MAX_PATH) {

libcxxabi/test/forced_unwind4.pass.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,7 @@
1717

1818
// Android/Bionic does not support pthread_cancel.
1919
#ifdef __BIONIC__
20-
int main() {
21-
return 0;
22-
}
20+
int main(int, char**) { return 0; }
2321
#else
2422

2523
#include <chrono>
@@ -45,7 +43,7 @@ static void* test(void* arg) {
4543
return (void*)1;
4644
}
4745

48-
int main() {
46+
int main(int, char**) {
4947
pthread_t child_thread;
5048
std::unique_lock<std::mutex> lk(cv_m);
5149
pthread_create(&child_thread, 0, test, (void*)0);

libcxxabi/test/native/AArch64/ra_sign_state.pass.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ void bazz() {
5353
}
5454
}
5555

56-
int main() {
56+
int main(int, char**) {
5757
try {
5858
bazz();
5959
} catch (int i) {

libunwind/test/aarch64_vg_unwind.pass.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,4 +62,7 @@ __attribute__((noinline)) void foo() {
6262
// smstop sm
6363
}
6464

65-
int main() { foo(); }
65+
int main(int, char **) {
66+
foo();
67+
return 0;
68+
}

libunwind/test/aix_signal_unwind.pass.sh.S

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,10 +126,11 @@ extern "C" __attribute__((noinline)) void foo() {
126126
bar();
127127
}
128128

129-
int main() {
129+
int main(int, char**) {
130130
// Set signal handler for SIGSEGV.
131131
signal(SIGSEGV, handler);
132132
foo();
133+
return 0;
133134
}
134135

135136
#else // Assembly code for abc().

libunwind/test/bad_unwind_info.pass.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,4 +77,7 @@ extern "C" void stepper() {
7777
assert(unw_step(&cursor) <= 0);
7878
}
7979

80-
int main() { bad_unwind_info(); }
80+
int main(int, char **) {
81+
bad_unwind_info();
82+
return 0;
83+
}

libunwind/test/eh_frame_fde_pc_range.pass.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121

2222
// RUN: %{build}
2323
// RUN: %{objcopy} --dump-section .eh_frame_hdr=%t_ehf_hdr.bin %t.exe
24-
// RUN: echo -ne '\xFF' | dd of=%t_ehf_hdr.bin bs=1 seek=2 count=2 conv=notrunc status=none
24+
// RUN: echo -ne '\xFF' | dd of=%t_ehf_hdr.bin bs=1 seek=2 count=2 conv=notrunc status=none
2525
// RUN: %{objcopy} --update-section .eh_frame_hdr=%t_ehf_hdr.bin %t.exe
2626
// RUN: %{exec} %t.exe
2727

@@ -53,7 +53,7 @@ void f() {
5353
assert(fde_fpc == fde_fpc1);
5454
}
5555

56-
int main() {
56+
int main(int, char **) {
5757
f();
5858
return 0;
5959
}

0 commit comments

Comments
 (0)