summaryrefslogtreecommitdiff
path: root/zen/string_traits.h
diff options
context:
space:
mode:
Diffstat (limited to 'zen/string_traits.h')
-rwxr-xr-xzen/string_traits.h8
1 files changed, 6 insertions, 2 deletions
diff --git a/zen/string_traits.h b/zen/string_traits.h
index 8187126d..cd7dbf1b 100755
--- a/zen/string_traits.h
+++ b/zen/string_traits.h
@@ -41,10 +41,14 @@ class StringRef
{
public:
template <class Iterator>
- StringRef(Iterator first, Iterator last) : len_(last - first), str_(first != last ? &*first : nullptr) {}
+ StringRef(Iterator first, Iterator last) : len_(last - first),
+ str_(first != last ? &*first : reinterpret_cast<Char*>(this) /*Win32 APIs like CompareStringOrdinal() choke on nullptr!*/)
+ {
+ static_assert(alignof(StringRef) % alignof(Char) == 0); //even though str_ is never dereferenced, make sure the pointer value respects alignment (why? because we can)
+ }
//StringRef(const Char* str, size_t len) : str_(str), len_(len) {} -> needless constraint! Char* not available for empty range!
- Char* data () const { return str_; } //1. no null-termination! 2. may be nullptr!
+ Char* data () const { return str_; } //no null-termination!
size_t length() const { return len_; }
private:
bgstack15