1 // Copyright 2023 The Chromium Authors
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
8 #include "testing/gtest/include/gtest/gtest.h"
16 bool operator<(const OneType& lhs, const OneType& rhs) {
17 return lhs.some_int < rhs.some_int;
24 // Verify libc++ hardening terminates instead of UB with invalid clamp args.
25 TEST(ClampTest, Death) {
26 EXPECT_DEATH_IF_SUPPORTED(std::ignore = std::clamp(3, 10, 0), "");
27 EXPECT_DEATH_IF_SUPPORTED(std::ignore = std::clamp(3.0, 10.0, 0.0), "");
29 OneType one_type_0{0};
30 OneType one_type_3{3};
31 OneType one_type_10{10};
32 AnotherType another_type_0{0};
33 AnotherType another_type_3{3};
34 AnotherType another_type_10{10};
35 auto compare_another_type = [](const auto& lhs, const auto& rhs) {
36 return lhs.some_other_int < rhs.some_other_int;
39 EXPECT_DEATH_IF_SUPPORTED(
40 std::ignore = std::clamp(one_type_3, one_type_10, one_type_0), "");
41 EXPECT_DEATH_IF_SUPPORTED(
42 std::ignore = std::clamp(another_type_3, another_type_10, another_type_0,
43 compare_another_type),