Movatterモバイル変換


[0]ホーム

URL:


Google Git
Sign in
chromium /chromium /src /refs/heads/main /. /base /std_clamp_unittest.cc
blob: 603378e1383b8d2ebcd4c35f0993f435f471c1a1 [file] [log] [blame]
Ho Cheungb1dba172023-05-16 22:58:01[diff] [blame]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.
4
5#include<algorithm>
6#include<tuple>
7
8#include"testing/gtest/include/gtest/gtest.h"
9
10namespace{
11
12structOneType{
13int some_int;
14};
15
16booloperator<(constOneType& lhs,constOneType& rhs){
17return lhs.some_int< rhs.some_int;
18}
19
20structAnotherType{
21int some_other_int;
22};
23
danakj08de6c72023-09-26 17:57:50[diff] [blame]24// Verify libc++ hardening terminates instead of UB with invalid clamp args.
Ho Cheungb1dba172023-05-16 22:58:01[diff] [blame]25TEST(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),"");
28
29OneType one_type_0{0};
30OneType one_type_3{3};
31OneType one_type_10{10};
32AnotherType another_type_0{0};
33AnotherType another_type_3{3};
34AnotherType another_type_10{10};
35auto compare_another_type=[](constauto& lhs,constauto& rhs){
36return lhs.some_other_int< rhs.some_other_int;
37};
38
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),
44"");
45}
46
47}// namespace

[8]ページ先頭

©2009-2025 Movatter.jp