summaryrefslogtreecommitdiff
path: root/libstdc++-v3/testsuite
diff options
context:
space:
mode:
authorJonathan Wakely <jwakely@redhat.com>2022-07-01 11:40:29 +0100
committerJonathan Wakely <jwakely@redhat.com>2022-07-01 11:50:18 +0100
commitf7a148304a71f3d3ad6845b7966fdc3af88c9e45 (patch)
tree169d21fb9e406517c960e42f57c529a5e56589f3 /libstdc++-v3/testsuite
parent7780dc5b2d02785186583fc8eced3c9e3aec4552 (diff)
libstdc++: Add nodiscard attribute to filesystem operations
Some of these are not truly "pure" because they access the file system, e.g. exists and file_size, but they do not modify anything and are only useful for the return value. If you really want to use one of those functions just to check whether an error is reported (either via an exception or an error_code& argument) you can still do so, but you need to cast the discarded result to void. Several tests need such a change, because they were indeed only calling the functions to check for expected errors. libstdc++-v3/ChangeLog: * include/bits/fs_ops.h: Add nodiscard to all pure functions. * include/experimental/bits/fs_ops.h: Likewise. * testsuite/27_io/filesystem/operations/all.cc: Do not discard results of absolute and canonical. * testsuite/27_io/filesystem/operations/absolute.cc: Cast discarded result to void. * testsuite/27_io/filesystem/operations/canonical.cc: Likewise. * testsuite/27_io/filesystem/operations/exists.cc: Likewise. * testsuite/27_io/filesystem/operations/is_empty.cc: Likewise. * testsuite/27_io/filesystem/operations/read_symlink.cc: Likewise. * testsuite/27_io/filesystem/operations/status.cc: Likewise. * testsuite/27_io/filesystem/operations/symlink_status.cc: Likewise. * testsuite/27_io/filesystem/operations/temp_directory_path.cc: Likewise. * testsuite/experimental/filesystem/operations/canonical.cc: Likewise. * testsuite/experimental/filesystem/operations/exists.cc: Likewise. * testsuite/experimental/filesystem/operations/is_empty.cc: Likewise. * testsuite/experimental/filesystem/operations/read_symlink.cc: Likewise. * testsuite/experimental/filesystem/operations/temp_directory_path.cc: Likewise.
Diffstat (limited to 'libstdc++-v3/testsuite')
-rw-r--r--libstdc++-v3/testsuite/27_io/filesystem/operations/absolute.cc2
-rw-r--r--libstdc++-v3/testsuite/27_io/filesystem/operations/all.cc8
-rw-r--r--libstdc++-v3/testsuite/27_io/filesystem/operations/canonical.cc4
-rw-r--r--libstdc++-v3/testsuite/27_io/filesystem/operations/exists.cc2
-rw-r--r--libstdc++-v3/testsuite/27_io/filesystem/operations/is_empty.cc4
-rw-r--r--libstdc++-v3/testsuite/27_io/filesystem/operations/read_symlink.cc2
-rw-r--r--libstdc++-v3/testsuite/27_io/filesystem/operations/status.cc2
-rw-r--r--libstdc++-v3/testsuite/27_io/filesystem/operations/symlink_status.cc2
-rw-r--r--libstdc++-v3/testsuite/27_io/filesystem/operations/temp_directory_path.cc4
-rw-r--r--libstdc++-v3/testsuite/experimental/filesystem/operations/canonical.cc6
-rw-r--r--libstdc++-v3/testsuite/experimental/filesystem/operations/exists.cc2
-rw-r--r--libstdc++-v3/testsuite/experimental/filesystem/operations/is_empty.cc4
-rw-r--r--libstdc++-v3/testsuite/experimental/filesystem/operations/read_symlink.cc2
-rw-r--r--libstdc++-v3/testsuite/experimental/filesystem/operations/temp_directory_path.cc4
14 files changed, 24 insertions, 24 deletions
diff --git a/libstdc++-v3/testsuite/27_io/filesystem/operations/absolute.cc b/libstdc++-v3/testsuite/27_io/filesystem/operations/absolute.cc
index 236e1b2fad7..295b755ada7 100644
--- a/libstdc++-v3/testsuite/27_io/filesystem/operations/absolute.cc
+++ b/libstdc++-v3/testsuite/27_io/filesystem/operations/absolute.cc
@@ -84,7 +84,7 @@ test03()
VERIFY( eabs.empty() );
try {
- absolute(path{});
+ (void) absolute(path{});
VERIFY( false );
} catch (const std::filesystem::filesystem_error& e) {
VERIFY( e.code() == std::errc::invalid_argument );
diff --git a/libstdc++-v3/testsuite/27_io/filesystem/operations/all.cc b/libstdc++-v3/testsuite/27_io/filesystem/operations/all.cc
index d5d6c8731c3..3c8ab78b78a 100644
--- a/libstdc++-v3/testsuite/27_io/filesystem/operations/all.cc
+++ b/libstdc++-v3/testsuite/27_io/filesystem/operations/all.cc
@@ -42,11 +42,11 @@ main()
bool b [[maybe_unused]];
std::uintmax_t size;
- std::filesystem::absolute(p);
- std::filesystem::absolute(p, ec);
+ p2 = std::filesystem::absolute(p);
+ p2 = std::filesystem::absolute(p, ec);
- std::filesystem::canonical(p);
- std::filesystem::canonical(p, ec);
+ p2 = std::filesystem::canonical(p);
+ p2 = std::filesystem::canonical(p, ec);
std::filesystem::copy(p, p);
std::filesystem::copy(p, p, ec);
diff --git a/libstdc++-v3/testsuite/27_io/filesystem/operations/canonical.cc b/libstdc++-v3/testsuite/27_io/filesystem/operations/canonical.cc
index 9c432b25acf..cb916a6f6b9 100644
--- a/libstdc++-v3/testsuite/27_io/filesystem/operations/canonical.cc
+++ b/libstdc++-v3/testsuite/27_io/filesystem/operations/canonical.cc
@@ -31,7 +31,7 @@ test01()
const std::error_code bad_ec = make_error_code(std::errc::invalid_argument);
std::error_code ec;
auto p = __gnu_test::nonexistent_path();
- canonical( p, ec );
+ (void) canonical( p, ec );
VERIFY( ec );
create_directory(p);
@@ -90,7 +90,7 @@ test02()
#if __cpp_exceptions
fs::path e1, e2;
try {
- canonical(p);
+ (void) canonical(p);
} catch (const fs::filesystem_error& e) {
e1 = e.path1();
e2 = e.path2();
diff --git a/libstdc++-v3/testsuite/27_io/filesystem/operations/exists.cc b/libstdc++-v3/testsuite/27_io/filesystem/operations/exists.cc
index b3063564ab4..f9956970b25 100644
--- a/libstdc++-v3/testsuite/27_io/filesystem/operations/exists.cc
+++ b/libstdc++-v3/testsuite/27_io/filesystem/operations/exists.cc
@@ -95,7 +95,7 @@ test04()
ec.clear();
try
{
- exists(unr);
+ (void) exists(unr);
}
catch(const std::filesystem::filesystem_error& ex)
{
diff --git a/libstdc++-v3/testsuite/27_io/filesystem/operations/is_empty.cc b/libstdc++-v3/testsuite/27_io/filesystem/operations/is_empty.cc
index 23246a4228c..d1dfd9f6dda 100644
--- a/libstdc++-v3/testsuite/27_io/filesystem/operations/is_empty.cc
+++ b/libstdc++-v3/testsuite/27_io/filesystem/operations/is_empty.cc
@@ -40,7 +40,7 @@ test01()
VERIFY( !result );
try {
- fs::is_empty(p);
+ (void) fs::is_empty(p);
} catch (const fs::filesystem_error& e) {
ec2 = e.code();
}
@@ -51,7 +51,7 @@ test01()
VERIFY( !result );
try {
- fs::is_empty(p/"f");
+ (void) fs::is_empty(p/"f");
} catch (const fs::filesystem_error& e) {
ec2 = e.code();
}
diff --git a/libstdc++-v3/testsuite/27_io/filesystem/operations/read_symlink.cc b/libstdc++-v3/testsuite/27_io/filesystem/operations/read_symlink.cc
index 030d6271de5..28be8cc3a64 100644
--- a/libstdc++-v3/testsuite/27_io/filesystem/operations/read_symlink.cc
+++ b/libstdc++-v3/testsuite/27_io/filesystem/operations/read_symlink.cc
@@ -31,7 +31,7 @@ test01()
auto p = __gnu_test::nonexistent_path();
std::error_code ec;
- read_symlink(p, ec);
+ (void) read_symlink(p, ec);
VERIFY( ec );
fs::path tgt = ".";
diff --git a/libstdc++-v3/testsuite/27_io/filesystem/operations/status.cc b/libstdc++-v3/testsuite/27_io/filesystem/operations/status.cc
index f2d2582ce41..c43ba29fd7f 100644
--- a/libstdc++-v3/testsuite/27_io/filesystem/operations/status.cc
+++ b/libstdc++-v3/testsuite/27_io/filesystem/operations/status.cc
@@ -74,7 +74,7 @@ test03()
std::error_code ec2;
fs::path p, p2;
try {
- fs::symlink_status(f.path);
+ (void) fs::symlink_status(f.path);
} catch (const fs::filesystem_error& e) {
caught = true;
p = e.path1();
diff --git a/libstdc++-v3/testsuite/27_io/filesystem/operations/symlink_status.cc b/libstdc++-v3/testsuite/27_io/filesystem/operations/symlink_status.cc
index e00e4aaa78e..c8fa5c0f27f 100644
--- a/libstdc++-v3/testsuite/27_io/filesystem/operations/symlink_status.cc
+++ b/libstdc++-v3/testsuite/27_io/filesystem/operations/symlink_status.cc
@@ -96,7 +96,7 @@ test03()
std::error_code ec2;
fs::path p, p2;
try {
- fs::symlink_status(f.path);
+ (void) fs::symlink_status(f.path);
} catch (const fs::filesystem_error& e) {
caught = true;
p = e.path1();
diff --git a/libstdc++-v3/testsuite/27_io/filesystem/operations/temp_directory_path.cc b/libstdc++-v3/testsuite/27_io/filesystem/operations/temp_directory_path.cc
index 56bd7408c2d..09d97c5e01c 100644
--- a/libstdc++-v3/testsuite/27_io/filesystem/operations/temp_directory_path.cc
+++ b/libstdc++-v3/testsuite/27_io/filesystem/operations/temp_directory_path.cc
@@ -117,7 +117,7 @@ test03()
std::error_code ec2;
try {
- fs::temp_directory_path();
+ (void) fs::temp_directory_path();
} catch (const fs::filesystem_error& e) {
ec2 = e.code();
}
@@ -142,7 +142,7 @@ test04()
std::error_code ec2;
std::string failed_path;
try {
- fs::temp_directory_path();
+ (void) fs::temp_directory_path();
} catch (const fs::filesystem_error& e) {
ec2 = e.code();
// On Windows the returned path will be in preferred form, i.e. using L'\\'
diff --git a/libstdc++-v3/testsuite/experimental/filesystem/operations/canonical.cc b/libstdc++-v3/testsuite/experimental/filesystem/operations/canonical.cc
index aef6725d776..92772db73ed 100644
--- a/libstdc++-v3/testsuite/experimental/filesystem/operations/canonical.cc
+++ b/libstdc++-v3/testsuite/experimental/filesystem/operations/canonical.cc
@@ -30,11 +30,11 @@ test01()
{
std::error_code ec;
auto p = __gnu_test::nonexistent_path();
- canonical( p, ec );
+ (void) canonical( p, ec );
VERIFY( ec );
p = fs::current_path();
- canonical( p, ec );
+ (void) canonical( p, ec );
VERIFY( !ec );
const auto root = fs::absolute("/");
@@ -67,7 +67,7 @@ test02()
fs::path p = "rel", base = __gnu_test::nonexistent_path();
fs::path e1, e2;
try {
- canonical(p, base);
+ (void) canonical(p, base);
} catch (const fs::filesystem_error& e) {
e1 = e.path1();
e2 = e.path2();
diff --git a/libstdc++-v3/testsuite/experimental/filesystem/operations/exists.cc b/libstdc++-v3/testsuite/experimental/filesystem/operations/exists.cc
index 5c274d073c2..271aff9717f 100644
--- a/libstdc++-v3/testsuite/experimental/filesystem/operations/exists.cc
+++ b/libstdc++-v3/testsuite/experimental/filesystem/operations/exists.cc
@@ -89,7 +89,7 @@ test04()
ec.clear();
try
{
- exists(unr);
+ (void) exists(unr);
}
catch(const std::experimental::filesystem::filesystem_error& ex)
{
diff --git a/libstdc++-v3/testsuite/experimental/filesystem/operations/is_empty.cc b/libstdc++-v3/testsuite/experimental/filesystem/operations/is_empty.cc
index 747236379e4..da21c8da0be 100644
--- a/libstdc++-v3/testsuite/experimental/filesystem/operations/is_empty.cc
+++ b/libstdc++-v3/testsuite/experimental/filesystem/operations/is_empty.cc
@@ -41,7 +41,7 @@ test01()
VERIFY( !result );
try {
- fs::is_empty(p);
+ (void) fs::is_empty(p);
} catch (const fs::filesystem_error& e) {
ec2 = e.code();
}
@@ -52,7 +52,7 @@ test01()
VERIFY( !result );
try {
- fs::is_empty(p/"f");
+ (void) fs::is_empty(p/"f");
} catch (const fs::filesystem_error& e) {
ec2 = e.code();
}
diff --git a/libstdc++-v3/testsuite/experimental/filesystem/operations/read_symlink.cc b/libstdc++-v3/testsuite/experimental/filesystem/operations/read_symlink.cc
index d0a90976a71..a29ceeb3499 100644
--- a/libstdc++-v3/testsuite/experimental/filesystem/operations/read_symlink.cc
+++ b/libstdc++-v3/testsuite/experimental/filesystem/operations/read_symlink.cc
@@ -32,7 +32,7 @@ test01()
auto p = __gnu_test::nonexistent_path();
std::error_code ec;
- read_symlink(p, ec);
+ (void) read_symlink(p, ec);
VERIFY( ec );
fs::path tgt = ".";
diff --git a/libstdc++-v3/testsuite/experimental/filesystem/operations/temp_directory_path.cc b/libstdc++-v3/testsuite/experimental/filesystem/operations/temp_directory_path.cc
index 1772f9737c1..d985f112f10 100644
--- a/libstdc++-v3/testsuite/experimental/filesystem/operations/temp_directory_path.cc
+++ b/libstdc++-v3/testsuite/experimental/filesystem/operations/temp_directory_path.cc
@@ -118,7 +118,7 @@ test03()
std::error_code ec2;
try {
- fs::temp_directory_path();
+ (void) fs::temp_directory_path();
} catch (const fs::filesystem_error& e) {
ec2 = e.code();
}
@@ -143,7 +143,7 @@ test04()
std::error_code ec2;
std::string failed_path;
try {
- fs::temp_directory_path();
+ (void) fs::temp_directory_path();
} catch (const fs::filesystem_error& e) {
ec2 = e.code();
// On Windows the returned path will be in preferred form, i.e. using L'\\'