Skip to content

Commit 0889809

Browse files
authored
[libc] Fix warning on 'extern "C" int main' in test suite (#102973)
Summary: According to the C++ standard, The main function shall not be declared with a linkage-specification. after some changes in #101853 this started emitting warnings when building / testing the C library. This source file is shared with the overlay tests as well as the full build tests. The full build tests are compiled with `-ffreestanding`, as are all the startup / integration files. The standard says freestanding environment are all implementation defined, so this is valid in those cases. This patch simply prevents adding the linkage when we are compiling unit tests, which are hosted. This is a continuation on #102825.
1 parent b1edac0 commit 0889809

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

libc/test/UnitTest/LibcTestMain.cpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,15 @@ TestOptions parseOptions(int argc, char **argv) {
4343

4444
} // anonymous namespace
4545

46-
extern "C" int main(int argc, char **argv, char **envp) {
46+
// The C++ standard forbids declaring the main function with a linkage specifier
47+
// outisde of 'freestanding' mode, only define the linkage for hermetic tests.
48+
#if __STDC_HOSTED__
49+
#define TEST_MAIN int main
50+
#else
51+
#define TEST_MAIN extern "C" int main
52+
#endif
53+
54+
TEST_MAIN(int argc, char **argv, char **envp) {
4755
LIBC_NAMESPACE::testing::argc = argc;
4856
LIBC_NAMESPACE::testing::argv = argv;
4957
LIBC_NAMESPACE::testing::envp = envp;

0 commit comments

Comments
 (0)