Skip to content

[NFC][libc++][exceptions] Adds tests for LWG3112. #100881

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 4, 2024

Conversation

mordante
Copy link
Member

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

@mordante mordante requested a review from a team as a code owner July 27, 2024 17:35
@llvmbot llvmbot added the libc++ libc++ C++ Standard Library. Not GNU libstdc++. Not libc++abi. label Jul 27, 2024
@llvmbot
Copy link
Member

llvmbot commented Jul 27, 2024

@llvm/pr-subscribers-libcxx

Author: Mark de Wever (mordante)

Changes

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

Full diff: https://github.com/llvm/llvm-project/pull/100881.diff

4 Files Affected:

  • (modified) libcxx/docs/Status/Cxx20Issues.csv (+1-1)
  • (modified) libcxx/test/std/diagnostics/syserr/syserr.syserr/syserr.syserr.members/ctor_error_code_string.pass.cpp (+2-1)
  • (modified) libcxx/test/std/diagnostics/syserr/syserr.syserr/syserr.syserr.members/ctor_int_error_category_string.pass.cpp (+2-1)
  • (modified) libcxx/test/std/input.output/filesystems/class.filesystem_error/filesystem_error.members.pass.cpp (+3-3)
diff --git a/libcxx/docs/Status/Cxx20Issues.csv b/libcxx/docs/Status/Cxx20Issues.csv
index 97ecf5e8e05a0..5d5b02ce5ad7e 100644
--- a/libcxx/docs/Status/Cxx20Issues.csv
+++ b/libcxx/docs/Status/Cxx20Issues.csv
@@ -134,7 +134,7 @@
 "`3077 <https://wg21.link/LWG3077>`__","``(push|emplace)_back``\  should invalidate the ``end``\  iterator","Kona","|Nothing To Do|",""
 "`3087 <https://wg21.link/LWG3087>`__","One final ``&x``\  in |sect|\ [list.ops]","Kona","|Nothing To Do|",""
 "`3101 <https://wg21.link/LWG3101>`__","``span``\ 's ``Container``\  constructors need another constraint","Kona","|Complete|",""
-"`3112 <https://wg21.link/LWG3112>`__","``system_error``\  and ``filesystem_error``\  constructors taking a ``string``\  may not be able to meet their postconditions","Kona","",""
+"`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|",""
 "`3119 <https://wg21.link/LWG3119>`__","Program-definedness of closure types","Kona","|Nothing To Do|",""
 "`3133 <https://wg21.link/LWG3133>`__","Modernizing numeric type requirements","Kona","",""
 "`3144 <https://wg21.link/LWG3144>`__","``span``\  does not have a ``const_pointer``\  typedef","Kona","|Complete|",""
diff --git a/libcxx/test/std/diagnostics/syserr/syserr.syserr/syserr.syserr.members/ctor_error_code_string.pass.cpp b/libcxx/test/std/diagnostics/syserr/syserr.syserr/syserr.syserr.members/ctor_error_code_string.pass.cpp
index a464084e55c50..d9640b0e1dcac 100644
--- a/libcxx/test/std/diagnostics/syserr/syserr.syserr/syserr.syserr.members/ctor_error_code_string.pass.cpp
+++ b/libcxx/test/std/diagnostics/syserr/syserr.syserr/syserr.syserr.members/ctor_error_code_string.pass.cpp
@@ -21,11 +21,12 @@
 #include "test_macros.h"
 
 int main(int, char**) {
-    std::string what_arg("test message");
+    std::string what_arg("test message\0With embedded NUL");
     std::system_error se(make_error_code(std::errc::not_a_directory), what_arg);
     assert(se.code() == std::make_error_code(std::errc::not_a_directory));
     std::string what_message(se.what());
     assert(what_message.find(what_arg) != std::string::npos);
+    assert(what_message.find(what_arg.c_str()) != std::string::npos);
     assert(what_message.find("Not a directory") != std::string::npos);
 
     return 0;
diff --git a/libcxx/test/std/diagnostics/syserr/syserr.syserr/syserr.syserr.members/ctor_int_error_category_string.pass.cpp b/libcxx/test/std/diagnostics/syserr/syserr.syserr/syserr.syserr.members/ctor_int_error_category_string.pass.cpp
index 2626fb8cc1f22..f7babf49e5e14 100644
--- a/libcxx/test/std/diagnostics/syserr/syserr.syserr/syserr.syserr.members/ctor_int_error_category_string.pass.cpp
+++ b/libcxx/test/std/diagnostics/syserr/syserr.syserr/syserr.syserr.members/ctor_int_error_category_string.pass.cpp
@@ -21,12 +21,13 @@
 #include "test_macros.h"
 
 int main(int, char**) {
-    std::string what_arg("test message");
+    std::string what_arg("test message\0With embedded NUL");
     std::system_error se(static_cast<int>(std::errc::not_a_directory),
                          std::generic_category(), what_arg);
     assert(se.code() == std::make_error_code(std::errc::not_a_directory));
     std::string what_message(se.what());
     assert(what_message.find(what_arg) != std::string::npos);
+    assert(what_message.find(what_arg.c_str()) != std::string::npos);
     assert(what_message.find("Not a directory") != std::string::npos);
 
     return 0;
diff --git a/libcxx/test/std/input.output/filesystems/class.filesystem_error/filesystem_error.members.pass.cpp b/libcxx/test/std/input.output/filesystems/class.filesystem_error/filesystem_error.members.pass.cpp
index fd77810cfa50b..89818072746a5 100644
--- a/libcxx/test/std/input.output/filesystems/class.filesystem_error/filesystem_error.members.pass.cpp
+++ b/libcxx/test/std/input.output/filesystems/class.filesystem_error/filesystem_error.members.pass.cpp
@@ -33,13 +33,13 @@ namespace fs = std::filesystem;
 void test_constructors() {
   using namespace fs;
 
-  // The string returned by "filesystem_error::what() must contain runtime_error::what()
-  const std::string what_arg = "Hello World";
+  // The string returned by "filesystem_error::what() must contain runtime_error::what().c_str()
+  const std::string what_arg = "Hello World\0with embedded NUL";
   const std::string what_contains = std::runtime_error(what_arg).what();
   assert(what_contains.find(what_arg) != std::string::npos);
   auto CheckWhat = [what_contains](filesystem_error const& e) {
     std::string s = e.what();
-    assert(s.find(what_contains) != std::string::npos);
+    assert(s.find(what_contains.c_str()) != std::string::npos);
   };
 
   std::error_code ec = std::make_error_code(std::errc::file_exists);

Copy link

github-actions bot commented Jul 27, 2024

✅ With the latest revision this PR passed the C/C++ code formatter.

Copy link
Member

@ldionne ldionne left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM w/ small comment.

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
@mordante mordante merged commit bfe0968 into llvm:main Aug 4, 2024
52 of 54 checks passed
@mordante mordante deleted the review/LWG3112 branch August 4, 2024 13:49
shiltian pushed a commit that referenced this pull request Aug 6, 2024
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
libc++ libc++ C++ Standard Library. Not GNU libstdc++. Not libc++abi.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

LWG3112: system_error and filesystem_error constructors taking a string may not be able to meet their postconditions
3 participants