File tree Expand file tree Collapse file tree 2 files changed +12
-2
lines changed Expand file tree Collapse file tree 2 files changed +12
-2
lines changed Original file line number Diff line number Diff line change @@ -55,7 +55,7 @@ struct Align {
55
55
56
56
public:
57
57
// / Default is byte-aligned.
58
- Align () = default;
58
+ constexpr Align () = default;
59
59
// / Do not perform checks in case of copy/move construct/assign, because the
60
60
// / checks have been performed when building `Other`.
61
61
Align (const Align &Other) = default;
@@ -73,6 +73,13 @@ struct Align {
73
73
// / This is a hole in the type system and should not be abused.
74
74
// / Needed to interact with C for instance.
75
75
uint64_t value () const { return uint64_t (1 ) << ShiftValue; }
76
+
77
+ // / Returns a default constructed Align which corresponds to no alignment.
78
+ // / This is useful to test for unalignment as it conveys clear semantic.
79
+ // / `if (A != llvm::Align::None())`
80
+ // / would be better than
81
+ // / `if (A > llvm::Align(1))`
82
+ constexpr static const Align None () { return llvm::Align (); }
76
83
};
77
84
78
85
// / Treats the value 0 as a 1, so Align is always at least 1.
Original file line number Diff line number Diff line change @@ -28,7 +28,10 @@ std::vector<uint64_t> getValidAlignments() {
28
28
return Out;
29
29
}
30
30
31
- TEST (AlignmentTest, AlignDefaultCTor) { EXPECT_EQ (Align ().value (), 1ULL ); }
31
+ TEST (AlignmentTest, AlignDefaultCTor) {
32
+ EXPECT_EQ (Align ().value (), 1ULL );
33
+ EXPECT_EQ (Align::None ().value (), 1ULL );
34
+ }
32
35
33
36
TEST (AlignmentTest, MaybeAlignDefaultCTor) {
34
37
EXPECT_FALSE (MaybeAlign ().hasValue ());
You can’t perform that action at this time.
0 commit comments