Skip to content

Commit eb7eaa6

Browse files
committed
[NFC][libc++][exceptions] Adds tests for LWG3112.
The tests kept being based on std::string instead of std::string_view to allow testing with older C++ dialects. Adds tests for: - LWG3112 system_error and filesystem_error constructors taking a string may not be able to meet their postconditions
1 parent 803eaf2 commit eb7eaa6

File tree

4 files changed

+8
-6
lines changed

4 files changed

+8
-6
lines changed

libcxx/docs/Status/Cxx20Issues.csv

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@
134134
"`3077 <https://wg21.link/LWG3077>`__","``(push|emplace)_back``\ should invalidate the ``end``\ iterator","Kona","|Nothing To Do|",""
135135
"`3087 <https://wg21.link/LWG3087>`__","One final ``&x``\ in |sect|\ [list.ops]","Kona","|Nothing To Do|",""
136136
"`3101 <https://wg21.link/LWG3101>`__","``span``\ 's ``Container``\ constructors need another constraint","Kona","|Complete|",""
137-
"`3112 <https://wg21.link/LWG3112>`__","``system_error``\ and ``filesystem_error``\ constructors taking a ``string``\ may not be able to meet their postconditions","Kona","",""
137+
"`3112 <https://wg21.link/LWG3112>`__","``system_error``\ and ``filesystem_error``\ constructors taking a ``string``\ may not be able to meet their postconditions","Kona","|Nothing To Do|",""
138138
"`3119 <https://wg21.link/LWG3119>`__","Program-definedness of closure types","Kona","|Nothing To Do|",""
139139
"`3133 <https://wg21.link/LWG3133>`__","Modernizing numeric type requirements","Kona","",""
140140
"`3144 <https://wg21.link/LWG3144>`__","``span``\ does not have a ``const_pointer``\ typedef","Kona","|Complete|",""

libcxx/test/std/diagnostics/syserr/syserr.syserr/syserr.syserr.members/ctor_error_code_string.pass.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,12 @@
2121
#include "test_macros.h"
2222

2323
int main(int, char**) {
24-
std::string what_arg("test message");
24+
std::string what_arg("test message\0With embedded NUL");
2525
std::system_error se(make_error_code(std::errc::not_a_directory), what_arg);
2626
assert(se.code() == std::make_error_code(std::errc::not_a_directory));
2727
std::string what_message(se.what());
2828
assert(what_message.find(what_arg) != std::string::npos);
29+
assert(what_message.find(what_arg.c_str()) != std::string::npos);
2930
assert(what_message.find("Not a directory") != std::string::npos);
3031

3132
return 0;

libcxx/test/std/diagnostics/syserr/syserr.syserr/syserr.syserr.members/ctor_int_error_category_string.pass.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,13 @@
2121
#include "test_macros.h"
2222

2323
int main(int, char**) {
24-
std::string what_arg("test message");
24+
std::string what_arg("test message\0With embedded NUL");
2525
std::system_error se(static_cast<int>(std::errc::not_a_directory),
2626
std::generic_category(), what_arg);
2727
assert(se.code() == std::make_error_code(std::errc::not_a_directory));
2828
std::string what_message(se.what());
2929
assert(what_message.find(what_arg) != std::string::npos);
30+
assert(what_message.find(what_arg.c_str()) != std::string::npos);
3031
assert(what_message.find("Not a directory") != std::string::npos);
3132

3233
return 0;

libcxx/test/std/input.output/filesystems/class.filesystem_error/filesystem_error.members.pass.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,13 @@ namespace fs = std::filesystem;
3333
void test_constructors() {
3434
using namespace fs;
3535

36-
// The string returned by "filesystem_error::what() must contain runtime_error::what()
37-
const std::string what_arg = "Hello World";
36+
// The string returned by "filesystem_error::what() must contain runtime_error::what().c_str()
37+
const std::string what_arg = "Hello World\0with embedded NUL";
3838
const std::string what_contains = std::runtime_error(what_arg).what();
3939
assert(what_contains.find(what_arg) != std::string::npos);
4040
auto CheckWhat = [what_contains](filesystem_error const& e) {
4141
std::string s = e.what();
42-
assert(s.find(what_contains) != std::string::npos);
42+
assert(s.find(what_contains.c_str()) != std::string::npos);
4343
};
4444

4545
std::error_code ec = std::make_error_code(std::errc::file_exists);

0 commit comments

Comments
 (0)