Skip to content

Commit ac23d22

Browse files
committed
binder: declare main in global NS, w/o extern "C"
The main function should be in the global namespace, not the android namespace. We were using 'extern "C"' to prevent the mangling, but the C++ standard doesn't allow a linkage-specification for main, https://eel.is/c++draft/basic.start.main#3.sentence-5: "The main function shall not be declared with a linkage-specification ([dcl.link])." Clang has started warning on incorrect declarations of main (-Wmain). Bug: http://b/379133546 Test: m binder_thread_stats libbinderdebug_test binderSafeInterfaceTest Change-Id: I1c53ce621391b5577c8c04b21117e9b59fe05136
1 parent 99871bf commit ac23d22

3 files changed

Lines changed: 17 additions & 13 deletions

File tree

libs/binder/tests/binderSafeInterfaceTest.cpp

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -858,7 +858,13 @@ TEST_F(SafeInterfaceTest, TestIncrementTwo) {
858858
ASSERT_EQ(b + 1, bPlusOne);
859859
}
860860

861-
extern "C" int main(int argc, char **argv) {
861+
} // namespace tests
862+
} // namespace android
863+
864+
int main(int argc, char** argv) {
865+
using namespace android;
866+
using namespace android::tests;
867+
862868
testing::InitGoogleTest(&argc, argv);
863869

864870
if (fork() == 0) {
@@ -875,6 +881,3 @@ extern "C" int main(int argc, char **argv) {
875881

876882
return RUN_ALL_TESTS();
877883
}
878-
879-
} // namespace tests
880-
} // namespace android

libs/binderdebug/stats.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,9 @@
2222

2323
#include <inttypes.h>
2424

25-
namespace android {
25+
int main() {
26+
using namespace android;
2627

27-
extern "C" int main() {
2828
// ignore args - we only print csv
2929

3030
// we should use a csv library here for escaping, because
@@ -58,5 +58,3 @@ extern "C" int main() {
5858
}
5959
return 0;
6060
}
61-
62-
} // namespace android

libs/binderdebug/tests/binderdebug_test.cpp

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,15 @@ TEST(BinderDebugTests, BinderThreads) {
6060
EXPECT_GE(pidInfo.threadCount, 1);
6161
}
6262

63-
extern "C" {
63+
} // namespace test
64+
} // namespace binderdebug
65+
} // namespace android
66+
6467
int main(int argc, char** argv) {
68+
using namespace android;
69+
using namespace android::binderdebug;
70+
using namespace android::binderdebug::test;
71+
6572
::testing::InitGoogleTest(&argc, argv);
6673

6774
// Create a child/client process to call into the main process so we can ensure
@@ -84,7 +91,3 @@ int main(int argc, char** argv) {
8491

8592
return RUN_ALL_TESTS();
8693
}
87-
} // extern "C"
88-
} // namespace test
89-
} // namespace binderdebug
90-
} // namespace android

0 commit comments

Comments
 (0)