[automerger skipped] Merge "expected.h - fix bugprone-branch-clone warning" into rvc-dev am: 61e2b0104a am: 4979a4aff8 -s ours
am skip reason: Change-Id Ie67a8bb1bf622319adea15466c42077e0e9b1a18 with SHA-1 4fc9b99329 is in history
Change-Id: I7f419222a7a97c5896887f3c7e174caa5f4898b1
diff --git a/Android.bp b/Android.bp
index 5b91078..894ad6c 100644
--- a/Android.bp
+++ b/Android.bp
@@ -203,6 +203,23 @@
test_suites: ["device-tests"],
}
+cc_test {
+ name: "libbase_tidy_test",
+ defaults: ["libbase_cflags_defaults"],
+ host_supported: true,
+
+ tidy: true,
+ tidy_checks_as_errors: ["bugprone-use-after-move"],
+
+ srcs: [
+ "tidy/unique_fd_test.cpp",
+ "tidy/unique_fd_test2.cpp",
+ ],
+
+ shared_libs: ["libbase"],
+ test_suites: ["device_tests"],
+}
+
cc_benchmark {
name: "libbase_benchmark",
defaults: ["libbase_cflags_defaults"],
diff --git a/include/android-base/macros.h b/include/android-base/macros.h
index 5abf514..546b2ec 100644
--- a/include/android-base/macros.h
+++ b/include/android-base/macros.h
@@ -143,8 +143,4 @@
#define ABI_STRING "x86"
#elif defined(__x86_64__)
#define ABI_STRING "x86_64"
-#elif defined(__mips__) && !defined(__LP64__)
-#define ABI_STRING "mips"
-#elif defined(__mips__) && defined(__LP64__)
-#define ABI_STRING "mips64"
#endif
diff --git a/include/android-base/unique_fd.h b/include/android-base/unique_fd.h
index c4a0aad..9ceb5db 100644
--- a/include/android-base/unique_fd.h
+++ b/include/android-base/unique_fd.h
@@ -102,7 +102,7 @@
return *this;
}
- void reset(int new_value = -1) { reset(new_value, nullptr); }
+ [[clang::reinitializes]] void reset(int new_value = -1) { reset(new_value, nullptr); }
int get() const { return fd_; }
diff --git a/properties.cpp b/properties.cpp
index 35e41a8..5c9ec7e 100644
--- a/properties.cpp
+++ b/properties.cpp
@@ -133,7 +133,6 @@
ts.tv_nsec = ns.count();
}
-// TODO: boot_clock?
using AbsTime = std::chrono::time_point<std::chrono::steady_clock>;
static void UpdateTimeSpec(timespec& ts, std::chrono::milliseconds relative_timeout,
diff --git a/tidy/unique_fd_test.cpp b/tidy/unique_fd_test.cpp
new file mode 100644
index 0000000..b3a99fc
--- /dev/null
+++ b/tidy/unique_fd_test.cpp
@@ -0,0 +1,32 @@
+/*
+ * Copyright (C) 2020 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "android-base/unique_fd.h"
+
+#include <utility>
+
+#include <gtest/gtest.h>
+
+extern void consume_unique_fd(android::base::unique_fd fd);
+
+TEST(unique_fd, bugprone_use_after_move) {
+ // Compile time test for clang-tidy's bugprone-use-after-move check.
+ android::base::unique_fd ufd(open("/dev/null", O_RDONLY | O_CLOEXEC));
+ consume_unique_fd(std::move(ufd));
+ ufd.reset(open("/dev/null", O_RDONLY | O_CLOEXEC));
+ ufd.get();
+ consume_unique_fd(std::move(ufd));
+}
diff --git a/tidy/unique_fd_test2.cpp b/tidy/unique_fd_test2.cpp
new file mode 100644
index 0000000..b0c71e2
--- /dev/null
+++ b/tidy/unique_fd_test2.cpp
@@ -0,0 +1,19 @@
+/*
+ * Copyright (C) 2020 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "android-base/unique_fd.h"
+
+void consume_unique_fd(android::base::unique_fd) {}