Skip to content

Commit 4b77215

Browse files
authored
Harden operator wstring_view (#546)
1 parent 7b70db8 commit 4b77215

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

strings/base_string.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,7 @@ WINRT_EXPORT namespace winrt
233233
}
234234
else
235235
{
236-
return {};
236+
return { L"", 0 };
237237
}
238238
}
239239

test/test/hstring_empty.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,15 @@ TEST_CASE("hstring_empty")
1313
// Using wcslen to both validate that the strings are empty *and* that they are not null.
1414
REQUIRE(wcslen(s.c_str()) == 0);
1515
REQUIRE(wcslen(s.data()) == 0);
16+
17+
std::wstring_view v = s;
18+
REQUIRE(v.empty());
19+
REQUIRE(v.size() == 0);
20+
REQUIRE(v == L""sv);
21+
REQUIRE(std::distance(v.begin(), v.end()) == 0);
22+
23+
// Using wcslen to both validate that the strings are empty *and* that they are not null.
24+
// This is not guaranteed for wstring_view, but is assumed by some code that creates a
25+
// wstring_view from an hstring.
26+
REQUIRE(wcslen(v.data()) == 0);
1627
}

0 commit comments

Comments
 (0)