Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(643)

Side by Side Diff: base/bit_cast_unittest.cc

Issue 2583353002: Make bit_cast fail if the source or dest are not trivially copyable (Closed)
Patch Set: bitcast: fixes Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « base/bit_cast.h ('k') | base/template_util.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2016 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 5
6 #include "base/bit_cast.h" 6 #include "base/bit_cast.h"
7 7
8 #include "testing/gtest/include/gtest/gtest.h" 8 #include "testing/gtest/include/gtest/gtest.h"
9 9
10 namespace base { 10 namespace base {
11 namespace { 11 namespace {
12 12
13 TEST(BitCastTest, FloatIntFloat) { 13 TEST(BitCastTest, FloatIntFloat) {
14 float f = 3.1415926f; 14 float f = 3.1415926f;
15 int i = bit_cast<int32_t>(f); 15 int i = bit_cast<int32_t>(f);
16 float f2 = bit_cast<float>(i); 16 float f2 = bit_cast<float>(i);
17 EXPECT_EQ(f, f2); 17 EXPECT_EQ(f, f2);
18 } 18 }
19 19
20 struct A { 20 struct A {
21 int x; 21 int x;
22 }; 22 };
23 23
24 TEST(BitCastTest, StructureInt) { 24 TEST(BitCastTest, StructureInt) {
25 A a = { 1 }; 25 A a = { 1 };
26 int b = bit_cast<int>(a); 26 int b = bit_cast<int>(a);
27 EXPECT_EQ(1, b); 27 EXPECT_EQ(1, b);
28 } 28 }
29 29
30
31 } // namespace 30 } // namespace
32 } // namespace base 31 } // namespace base
OLDNEW
« no previous file with comments | « base/bit_cast.h ('k') | base/template_util.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698