1*8f0ba417SAndroid Build Coastguard Worker /* 2*8f0ba417SAndroid Build Coastguard Worker * Copyright (C) 2020 The Android Open Source Project 3*8f0ba417SAndroid Build Coastguard Worker * 4*8f0ba417SAndroid Build Coastguard Worker * Licensed under the Apache License, Version 2.0 (the "License"); 5*8f0ba417SAndroid Build Coastguard Worker * you may not use this file except in compliance with the License. 6*8f0ba417SAndroid Build Coastguard Worker * You may obtain a copy of the License at 7*8f0ba417SAndroid Build Coastguard Worker * 8*8f0ba417SAndroid Build Coastguard Worker * http://www.apache.org/licenses/LICENSE-2.0 9*8f0ba417SAndroid Build Coastguard Worker * 10*8f0ba417SAndroid Build Coastguard Worker * Unless required by applicable law or agreed to in writing, software 11*8f0ba417SAndroid Build Coastguard Worker * distributed under the License is distributed on an "AS IS" BASIS, 12*8f0ba417SAndroid Build Coastguard Worker * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13*8f0ba417SAndroid Build Coastguard Worker * See the License for the specific language governing permissions and 14*8f0ba417SAndroid Build Coastguard Worker * limitations under the License. 15*8f0ba417SAndroid Build Coastguard Worker */ 16*8f0ba417SAndroid Build Coastguard Worker 17*8f0ba417SAndroid Build Coastguard Worker #include "android-base/unique_fd.h" 18*8f0ba417SAndroid Build Coastguard Worker 19*8f0ba417SAndroid Build Coastguard Worker #include <utility> 20*8f0ba417SAndroid Build Coastguard Worker 21*8f0ba417SAndroid Build Coastguard Worker #include <gtest/gtest.h> 22*8f0ba417SAndroid Build Coastguard Worker 23*8f0ba417SAndroid Build Coastguard Worker extern void consume_unique_fd(android::base::unique_fd fd); 24*8f0ba417SAndroid Build Coastguard Worker TEST(unique_fd,bugprone_use_after_move)25*8f0ba417SAndroid Build Coastguard WorkerTEST(unique_fd, bugprone_use_after_move) { 26*8f0ba417SAndroid Build Coastguard Worker // Compile time test for clang-tidy's bugprone-use-after-move check. 27*8f0ba417SAndroid Build Coastguard Worker android::base::unique_fd ufd(open("/dev/null", O_RDONLY | O_CLOEXEC)); 28*8f0ba417SAndroid Build Coastguard Worker consume_unique_fd(std::move(ufd)); 29*8f0ba417SAndroid Build Coastguard Worker ufd.reset(open("/dev/null", O_RDONLY | O_CLOEXEC)); 30*8f0ba417SAndroid Build Coastguard Worker ufd.get(); 31*8f0ba417SAndroid Build Coastguard Worker consume_unique_fd(std::move(ufd)); 32*8f0ba417SAndroid Build Coastguard Worker } 33