Skip to content

Commit c542858

Browse files
author
Архипов Дмитрий
committed
Merge remote-tracking branch 'oiffrig/underlying_type'
2 parents d1fdfe0 + c3ba729 commit c542858

File tree

4 files changed

+18
-4
lines changed

4 files changed

+18
-4
lines changed

include/flags/flags.hpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -140,15 +140,15 @@ template <class E> class flags {
140140
}
141141

142142
friend constexpr flags operator|(flags f1, flags f2) noexcept {
143-
return flags{f1.val_ | f2.val_};
143+
return flags{static_cast<impl_type>(f1.val_ | f2.val_)};
144144
}
145145

146146
friend constexpr flags operator&(flags f1, flags f2) noexcept {
147-
return flags{f1.val_ & f2.val_};
147+
return flags{static_cast<impl_type>(f1.val_ & f2.val_)};
148148
}
149149

150150
friend constexpr flags operator^(flags f1, flags f2) noexcept {
151-
return flags{f1.val_ ^ f2.val_};
151+
return flags{static_cast<impl_type>(f1.val_ ^ f2.val_)};
152152
}
153153

154154

test/Jamroot

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import testing ;
33

44
project flags_tests
55
: requirements <warnings>all
6+
<warnings-as-errors>on
67
<cxxflags>-std=c++11
78
<include>../include/
89
: default-build <variant>release

test/common.hpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,10 @@ ALLOW_FLAGS_FOR_ENUM(Enum)
1111
using Enums = flags::flags<Enum>;
1212

1313

14+
enum class SmallEnum : unsigned char {SmallOne = 1, SmallTwo = 2, SmallFour = 4, SmallEight = 8};
15+
ALLOW_FLAGS_FOR_ENUM(SmallEnum)
16+
17+
using SmallEnums = flags::flags<SmallEnum>;
18+
19+
1420
#endif // ENUM_CLASS_TEST_COMMON_HPP

test/should-compile.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,11 +147,18 @@ constexpr Enums::iterator cf3 = ec1.find(Enum::One);
147147
constexpr Enums::size_type cf4 = ec1.count(Enum::One);
148148

149149

150+
// non-int underlying type with bitwise operators
151+
constexpr SmallEnums s1(SmallEnum::SmallOne);
152+
constexpr auto s2 = s1 | s1;
153+
constexpr auto s3 = s1 & s1;
154+
constexpr auto s4 = s1 ^ s1;
155+
156+
150157
template <class... Ts> void ignore_variables(Ts&&...) {}
151158

152159
void do_ignore_variables() {
153160
ignore_variables(
154161
vc1, vc2, l1, l2, l3, l4, b1, b2, b3, b4, b5, b6, b7, b8, b9, b10, b11,
155-
b12, b13, cv1, cf1, cf2, cf3, cf4
162+
b12, b13, cv1, cf1, cf2, cf3, cf4, s2, s3, s4
156163
);
157164
}

0 commit comments

Comments
 (0)