32 lines · cpp
1// RUN: %check_clang_tidy %s android-cloexec-dup %t2 3extern "C" int dup(int oldfd);4void f() {5 dup(1);6 // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: prefer fcntl() to dup() because fcntl() allows F_DUPFD_CLOEXEC [android-cloexec-dup]7 // CHECK-FIXES: fcntl(1, F_DUPFD_CLOEXEC);8 int oldfd = 0;9 dup(oldfd);10 // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: prefer11 // CHECK-FIXES: fcntl(oldfd, F_DUPFD_CLOEXEC);12}13 14namespace i {15int dup(int oldfd);16void g() {17 dup(0);18 int oldfd = 1;19 dup(oldfd);20}21} // namespace i22 23class C {24public:25 int dup(int oldfd);26 void h() {27 dup(0);28 int oldfd = 1;29 dup(oldfd);30 }31};32