diff options
Diffstat (limited to 'libcxx/test')
5 files changed, 103 insertions, 12 deletions
diff --git a/libcxx/test/benchmarks/containers/associative/associative_container_benchmarks.h b/libcxx/test/benchmarks/containers/associative/associative_container_benchmarks.h index b395698..22a6d0d 100644 --- a/libcxx/test/benchmarks/containers/associative/associative_container_benchmarks.h +++ b/libcxx/test/benchmarks/containers/associative/associative_container_benchmarks.h @@ -305,11 +305,19 @@ void associative_container_benchmarks(std::string container) { // The insert(hint, ...) methods are only relevant for ordered containers, and we lack // a good way to compute a hint for unordered ones. if constexpr (is_ordered_container) { - bench("insert(hint, value) (good hint)", [=](auto& st) { + auto insert_good_hint_bench = [=](bool bench_end_iter, auto& st) { const std::size_t size = st.range(0); std::vector<Value> in = make_value_types(generate_unique_keys(size + 1)); - Value to_insert = in.back(); - in.pop_back(); + auto skipped_val = bench_end_iter ? in.size() - 1 : in.size() / 2; + Value to_insert = in[skipped_val]; + { // Remove the element + std::vector<Value> tmp; + tmp.reserve(in.size() - 1); + for (size_t i = 0; i != in.size(); ++i) + if (i != skipped_val) + tmp.emplace_back(in[i]); + in = std::move(tmp); + } std::vector<Container> c(BatchSize, Container(in.begin(), in.end())); typename Container::iterator hints[BatchSize]; @@ -332,13 +340,23 @@ void associative_container_benchmarks(std::string container) { } st.ResumeTiming(); } - }); + }; + bench("insert(hint, value) (good hint, end)", [=](auto& state) { insert_good_hint_bench(true, state); }); + bench("insert(hint, value) (good hint, middle)", [=](auto& state) { insert_good_hint_bench(false, state); }); - bench("insert(hint, value) (bad hint)", [=](auto& st) { + auto insert_bad_hint_bench = [=](bool bench_end_iter, auto& st) { const std::size_t size = st.range(0); std::vector<Value> in = make_value_types(generate_unique_keys(size + 1)); - Value to_insert = in.back(); - in.pop_back(); + auto skipped_val = bench_end_iter ? in.size() - 1 : in.size() / 2; + Value to_insert = in[skipped_val]; + { // Remove the element + std::vector<Value> tmp; + tmp.reserve(in.size() - 1); + for (size_t i = 0; i != in.size(); ++i) + if (i != skipped_val) + tmp.emplace_back(in[i]); + in = std::move(tmp); + } std::vector<Container> c(BatchSize, Container(in.begin(), in.end())); while (st.KeepRunningBatch(BatchSize)) { @@ -355,7 +373,10 @@ void associative_container_benchmarks(std::string container) { } st.ResumeTiming(); } - }); + }; + + bench("insert(hint, value) (bad hint, end)", [=](auto& state) { insert_bad_hint_bench(true, state); }); + bench("insert(hint, value) (bad hint, middle)", [=](auto& state) { insert_bad_hint_bench(false, state); }); } bench("insert(iterator, iterator) (all new keys)", [=](auto& st) { diff --git a/libcxx/test/libcxx/diagnostics/atomic.nodiscard.verify.cpp b/libcxx/test/libcxx/diagnostics/atomic.nodiscard.verify.cpp new file mode 100644 index 0000000..85e5f0b --- /dev/null +++ b/libcxx/test/libcxx/diagnostics/atomic.nodiscard.verify.cpp @@ -0,0 +1,33 @@ +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +// REQUIRES: std-at-least-c++26 + +// check that <atomic> functions are marked [[nodiscard]] + +#include <atomic> + +#include "atomic_helpers.h" +#include "test_macros.h" + +template <typename T> +struct TestAtomicRef { + void operator()() const { + T x(T(1)); + const std::atomic_ref<T> a(x); + + a.address(); // expected-warning 4 {{ignoring return value of function declared with 'nodiscard' attribute}} + } +}; + +void test() { + TestAtomicRef<UserAtomicType>()(); + TestAtomicRef<int>()(); + TestAtomicRef<float>()(); + TestAtomicRef<char*>()(); +} diff --git a/libcxx/test/std/atomics/atomics.ref/address.pass.cpp b/libcxx/test/std/atomics/atomics.ref/address.pass.cpp new file mode 100644 index 0000000..e0db6a9 --- /dev/null +++ b/libcxx/test/std/atomics/atomics.ref/address.pass.cpp @@ -0,0 +1,37 @@ +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +// REQUIRES: std-at-least-c++26 + +// constexpr T* address() const noexcept; + +#include <atomic> +#include <cassert> +#include <concepts> +#include <memory> + +#include "atomic_helpers.h" +#include "test_macros.h" + +template <typename T> +struct TestAddress { + void operator()() const { + T x(T(1)); + const std::atomic_ref<T> a(x); + + std::same_as<T*> decltype(auto) p = a.address(); + assert(std::addressof(x) == p); + + static_assert(noexcept((a.address()))); + } +}; + +int main(int, char**) { + TestEachAtomicType<TestAddress>()(); + + return 0; +} diff --git a/libcxx/test/std/language.support/support.limits/support.limits.general/atomic.version.compile.pass.cpp b/libcxx/test/std/language.support/support.limits/support.limits.general/atomic.version.compile.pass.cpp index 93eb43c..8bd0274 100644 --- a/libcxx/test/std/language.support/support.limits/support.limits.general/atomic.version.compile.pass.cpp +++ b/libcxx/test/std/language.support/support.limits/support.limits.general/atomic.version.compile.pass.cpp @@ -355,8 +355,8 @@ # ifndef __cpp_lib_atomic_ref # error "__cpp_lib_atomic_ref should be defined in c++26" # endif -# if __cpp_lib_atomic_ref != 201806L -# error "__cpp_lib_atomic_ref should have the value 201806L in c++26" +# if __cpp_lib_atomic_ref != 202411L +# error "__cpp_lib_atomic_ref should have the value 202411L in c++26" # endif # if !defined(_LIBCPP_VERSION) diff --git a/libcxx/test/std/language.support/support.limits/support.limits.general/version.version.compile.pass.cpp b/libcxx/test/std/language.support/support.limits/support.limits.general/version.version.compile.pass.cpp index d1fd55f..05af1fb 100644 --- a/libcxx/test/std/language.support/support.limits/support.limits.general/version.version.compile.pass.cpp +++ b/libcxx/test/std/language.support/support.limits/support.limits.general/version.version.compile.pass.cpp @@ -6325,8 +6325,8 @@ # ifndef __cpp_lib_atomic_ref # error "__cpp_lib_atomic_ref should be defined in c++26" # endif -# if __cpp_lib_atomic_ref != 201806L -# error "__cpp_lib_atomic_ref should have the value 201806L in c++26" +# if __cpp_lib_atomic_ref != 202411L +# error "__cpp_lib_atomic_ref should have the value 202411L in c++26" # endif # if !defined(_LIBCPP_VERSION) |