diff options
author | Gabe Black <gabeblack@google.com> | 2018-01-07 18:38:04 -0800 |
---|---|---|
committer | Gabe Black <gabeblack@google.com> | 2018-01-20 07:29:56 +0000 |
commit | 0d56fdef7a60691c59e1782a5c5c0a532dcdeeea (patch) | |
tree | b78c0df7f4865944fe45d2120e4f3a5f66f0f501 /src/base/bituniontest.cc | |
parent | cd9450c1d95d9494e2714ec84620c548b0eebbb1 (diff) | |
download | gem5-0d56fdef7a60691c59e1782a5c5c0a532dcdeeea.tar.xz |
base: Enable specializing templates on BitUnion types.
Previously these relied on reaching into private internal definitions
in the BitUnion types.
Change-Id: Ia6c94de92986b85ec9e5fcb197459d450111fb36
Reviewed-on: https://gem5-review.googlesource.com/7202
Reviewed-by: Jason Lowe-Power <jason@lowepower.com>
Maintainer: Gabe Black <gabeblack@google.com>
Diffstat (limited to 'src/base/bituniontest.cc')
-rw-r--r-- | src/base/bituniontest.cc | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/src/base/bituniontest.cc b/src/base/bituniontest.cc index ed7b77b66..8781d2d5e 100644 --- a/src/base/bituniontest.cc +++ b/src/base/bituniontest.cc @@ -31,6 +31,7 @@ #include <cassert> #include <iostream> +#include <type_traits> #include "base/bitunion.hh" #include "base/cprintf.hh" @@ -140,6 +141,17 @@ class BitUnionData : public testing::Test { Split split; void SetUp() override { sixtyFour = 0; split = 0; } + + template <typename T> + uint64_t templatedFunction(T) { return 0; } + + template <typename T> + uint64_t + templatedFunction(BitUnionType<T> u) + { + BitUnionBaseType<T> b = u; + return b; + } }; TEST_F(BitUnionData, NormalBitfield) @@ -239,3 +251,22 @@ TEST_F(BitUnionData, Custom) EXPECT_EQ(split, 0xf0f0); EXPECT_EQ((uint64_t)split.split, 0xff); } + +TEST_F(BitUnionData, Templating) +{ + sixtyFour = 0xff; + EXPECT_EQ(templatedFunction(sixtyFour), 0xff); + EXPECT_EQ(templatedFunction((uint64_t)sixtyFour), 0); + + BitUnion(uint64_t, Dummy64) + EndBitUnion(Dummy64); + + BitUnion(uint32_t, Dummy32) + EndBitUnion(Dummy32); + + bool is64; + is64 = std::is_same<BitUnionBaseType<Dummy64>, uint64_t>::value; + EXPECT_TRUE(is64); + is64 = std::is_same<BitUnionBaseType<Dummy32>, uint64_t>::value; + EXPECT_FALSE(is64); +} |