summaryrefslogtreecommitdiff
path: root/libcxx/test
diff options
context:
space:
mode:
Diffstat (limited to 'libcxx/test')
-rw-r--r--libcxx/test/libcxx/utilities/any/nodiscard.verify.cpp45
-rw-r--r--libcxx/test/std/utilities/any/any.nonmembers/any.cast/any_cast_request_invalid_value_category.verify.cpp12
-rw-r--r--libcxx/test/std/utilities/any/any.nonmembers/any.cast/const_correctness.verify.cpp8
-rw-r--r--libcxx/test/std/utilities/any/any.nonmembers/any.cast/not_copy_constructible.verify.cpp8
-rw-r--r--libcxx/test/std/utilities/any/any.nonmembers/any.cast/reference_types.verify.cpp16
-rw-r--r--libcxx/test/std/utilities/any/any.nonmembers/any.cast/void.verify.cpp4
6 files changed, 69 insertions, 24 deletions
diff --git a/libcxx/test/libcxx/utilities/any/nodiscard.verify.cpp b/libcxx/test/libcxx/utilities/any/nodiscard.verify.cpp
new file mode 100644
index 000000000000..13a67bd3c304
--- /dev/null
+++ b/libcxx/test/libcxx/utilities/any/nodiscard.verify.cpp
@@ -0,0 +1,45 @@
+//===----------------------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+// REQUIRES: std-at-least-c++17
+
+// Check that functions are marked [[nodiscard]]
+
+#include <any>
+#include <utility>
+#include <vector>
+
+#include "test_macros.h"
+
+void test() {
+ std::any a{94};
+
+ // expected-warning@+1 {{ignoring return value of function declared with 'nodiscard' attribute}}
+ a.has_value();
+#if !defined(TEST_HAS_NO_RTTI)
+ // expected-warning@+1 {{ignoring return value of function declared with 'nodiscard' attribute}}
+ a.type();
+#endif
+
+ // expected-warning@+1 {{ignoring return value of function declared with 'nodiscard' attribute}}
+ std::make_any<int>(82);
+ // expected-warning@+1 {{ignoring return value of function declared with 'nodiscard' attribute}}
+ std::make_any<std::vector<int>>({94, 82, 50});
+
+ // expected-warning@+1 {{ignoring return value of function declared with 'nodiscard' attribute}}
+ std::any_cast<const int&>(std::as_const(a));
+ // expected-warning@+1 {{ignoring return value of function declared with 'nodiscard' attribute}}
+ std::any_cast<int&>(a);
+ // expected-warning@+1 {{ignoring return value of function declared with 'nodiscard' attribute}}
+ std::any_cast<int&&>(std::move(a));
+
+ // expected-warning@+1 {{ignoring return value of function declared with 'nodiscard' attribute}}
+ std::any_cast<int*>(&a);
+ // expected-warning@+1 {{ignoring return value of function declared with 'nodiscard' attribute}}
+ std::any_cast<const int*>(&std::as_const(a));
+}
diff --git a/libcxx/test/std/utilities/any/any.nonmembers/any.cast/any_cast_request_invalid_value_category.verify.cpp b/libcxx/test/std/utilities/any/any.nonmembers/any.cast/any_cast_request_invalid_value_category.verify.cpp
index c9800c5a0143..55e9923eab85 100644
--- a/libcxx/test/std/utilities/any/any.nonmembers/any.cast/any_cast_request_invalid_value_category.verify.cpp
+++ b/libcxx/test/std/utilities/any/any.nonmembers/any.cast/any_cast_request_invalid_value_category.verify.cpp
@@ -23,31 +23,31 @@ void test_const_lvalue_cast_request_non_const_lvalue() {
const std::any a;
// expected-error-re@any:* {{static assertion failed{{.*}}ValueType is required to be a const lvalue reference or a CopyConstructible type}}
// expected-error@any:* {{drops 'const' qualifier}}
- std::any_cast<TestType&>(a); // expected-note {{requested here}}
+ (void)std::any_cast<TestType&>(a); // expected-note {{requested here}}
const std::any a2(42);
// expected-error-re@any:* {{static assertion failed{{.*}}ValueType is required to be a const lvalue reference or a CopyConstructible type}}
// expected-error@any:* {{drops 'const' qualifier}}
- std::any_cast<int&>(a2); // expected-note {{requested here}}
+ (void)std::any_cast<int&>(a2); // expected-note {{requested here}}
}
void test_lvalue_any_cast_request_rvalue() {
std::any a;
// expected-error-re@any:* {{static assertion failed{{.*}}ValueType is required to be an lvalue reference or a CopyConstructible type}}
- std::any_cast<TestType&&>(a); // expected-note {{requested here}}
+ (void)std::any_cast<TestType&&>(a); // expected-note {{requested here}}
std::any a2(42);
// expected-error-re@any:* {{static assertion failed{{.*}}ValueType is required to be an lvalue reference or a CopyConstructible type}}
- std::any_cast<int&&>(a2); // expected-note {{requested here}}
+ (void)std::any_cast<int&&>(a2); // expected-note {{requested here}}
}
void test_rvalue_any_cast_request_lvalue() {
std::any a;
// expected-error-re@any:* {{static assertion failed{{.*}}ValueType is required to be an rvalue reference or a CopyConstructible type}}
// expected-error@any:* {{non-const lvalue reference to type 'TestType' cannot bind to a temporary}}
- std::any_cast<TestType&>(std::move(a)); // expected-note {{requested here}}
+ (void)std::any_cast<TestType&>(std::move(a)); // expected-note {{requested here}}
// expected-error-re@any:* {{static assertion failed{{.*}}ValueType is required to be an rvalue reference or a CopyConstructible type}}
// expected-error@any:* {{non-const lvalue reference to type 'int' cannot bind to a temporary}}
- std::any_cast<int&>(42);
+ (void)std::any_cast<int&>(42);
}
diff --git a/libcxx/test/std/utilities/any/any.nonmembers/any.cast/const_correctness.verify.cpp b/libcxx/test/std/utilities/any/any.nonmembers/any.cast/const_correctness.verify.cpp
index a60bb1bbc870..4ed1692b30a3 100644
--- a/libcxx/test/std/utilities/any/any.nonmembers/any.cast/const_correctness.verify.cpp
+++ b/libcxx/test/std/utilities/any/any.nonmembers/any.cast/const_correctness.verify.cpp
@@ -31,14 +31,14 @@ void test() {
std::any a;
// expected-error-re@any:* {{static assertion failed{{.*}}ValueType is required to be a const lvalue reference or a CopyConstructible type}}
- std::any_cast<TestType&>(static_cast<std::any const&>(a)); // expected-note {{requested here}}
+ (void)std::any_cast<TestType&>(static_cast<std::any const&>(a)); // expected-note {{requested here}}
// expected-error-re@any:* {{static assertion failed{{.*}}ValueType is required to be a const lvalue reference or a CopyConstructible type}}
- std::any_cast<TestType&&>(static_cast<std::any const&>(a)); // expected-note {{requested here}}
+ (void)std::any_cast<TestType&&>(static_cast<std::any const&>(a)); // expected-note {{requested here}}
// expected-error-re@any:* {{static assertion failed{{.*}}ValueType is required to be a const lvalue reference or a CopyConstructible type}}
- std::any_cast<TestType2&>(static_cast<std::any const&&>(a)); // expected-note {{requested here}}
+ (void)std::any_cast<TestType2&>(static_cast<std::any const&&>(a)); // expected-note {{requested here}}
// expected-error-re@any:* {{static assertion failed{{.*}}ValueType is required to be a const lvalue reference or a CopyConstructible type}}
- std::any_cast<TestType2&&>(static_cast<std::any const&&>(a)); // expected-note {{requested here}}
+ (void)std::any_cast<TestType2&&>(static_cast<std::any const&&>(a)); // expected-note {{requested here}}
}
diff --git a/libcxx/test/std/utilities/any/any.nonmembers/any.cast/not_copy_constructible.verify.cpp b/libcxx/test/std/utilities/any/any.nonmembers/any.cast/not_copy_constructible.verify.cpp
index 8b25d5ee520b..ad91455e7add 100644
--- a/libcxx/test/std/utilities/any/any.nonmembers/any.cast/not_copy_constructible.verify.cpp
+++ b/libcxx/test/std/utilities/any/any.nonmembers/any.cast/not_copy_constructible.verify.cpp
@@ -45,13 +45,13 @@ struct no_move {
void test() {
std::any a;
// expected-error-re@any:* {{static assertion failed{{.*}}ValueType is required to be an lvalue reference or a CopyConstructible type}}
- std::any_cast<no_copy>(static_cast<std::any&>(a)); // expected-note {{requested here}}
+ (void)std::any_cast<no_copy>(static_cast<std::any&>(a)); // expected-note {{requested here}}
// expected-error-re@any:* {{static assertion failed{{.*}}ValueType is required to be a const lvalue reference or a CopyConstructible type}}
- std::any_cast<no_copy>(static_cast<std::any const&>(a)); // expected-note {{requested here}}
+ (void)std::any_cast<no_copy>(static_cast<std::any const&>(a)); // expected-note {{requested here}}
- std::any_cast<no_copy>(static_cast<std::any&&>(a)); // OK
+ (void)std::any_cast<no_copy>(static_cast<std::any&&>(a)); // OK
// expected-error-re@any:* {{static assertion failed{{.*}}ValueType is required to be an rvalue reference or a CopyConstructible type}}
- std::any_cast<no_move>(static_cast<std::any&&>(a));
+ (void)std::any_cast<no_move>(static_cast<std::any&&>(a));
}
diff --git a/libcxx/test/std/utilities/any/any.nonmembers/any.cast/reference_types.verify.cpp b/libcxx/test/std/utilities/any/any.nonmembers/any.cast/reference_types.verify.cpp
index a055dcbf7f39..d634f73291e0 100644
--- a/libcxx/test/std/utilities/any/any.nonmembers/any.cast/reference_types.verify.cpp
+++ b/libcxx/test/std/utilities/any/any.nonmembers/any.cast/reference_types.verify.cpp
@@ -22,28 +22,28 @@ void test() {
std::any a = 1;
// expected-error-re@any:* 1 {{static assertion failed{{.*}}_ValueType may not be a reference.}}
- std::any_cast<int&>(&a); // expected-note {{requested here}}
+ (void)std::any_cast<int&>(&a); // expected-note {{requested here}}
// expected-error-re@any:* 1 {{static assertion failed{{.*}}_ValueType may not be a reference.}}
- std::any_cast<int&&>(&a); // expected-note {{requested here}}
+ (void)std::any_cast<int&&>(&a); // expected-note {{requested here}}
// expected-error-re@any:* 1 {{static assertion failed{{.*}}_ValueType may not be a reference.}}
- std::any_cast<int const&>(&a); // expected-note {{requested here}}
+ (void)std::any_cast<int const&>(&a); // expected-note {{requested here}}
// expected-error-re@any:* 1 {{static assertion failed{{.*}}_ValueType may not be a reference.}}
- std::any_cast<int const&&>(&a); // expected-note {{requested here}}
+ (void)std::any_cast<int const&&>(&a); // expected-note {{requested here}}
const std::any& a2 = a;
// expected-error-re@any:* 1 {{static assertion failed{{.*}}_ValueType may not be a reference.}}
- std::any_cast<int&>(&a2); // expected-note {{requested here}}
+ (void)std::any_cast<int&>(&a2); // expected-note {{requested here}}
// expected-error-re@any:* 1 {{static assertion failed{{.*}}_ValueType may not be a reference.}}
- std::any_cast<int&&>(&a2); // expected-note {{requested here}}
+ (void)std::any_cast<int&&>(&a2); // expected-note {{requested here}}
// expected-error-re@any:* 1 {{static assertion failed{{.*}}_ValueType may not be a reference.}}
- std::any_cast<int const&>(&a2); // expected-note {{requested here}}
+ (void)std::any_cast<int const&>(&a2); // expected-note {{requested here}}
// expected-error-re@any:* 1 {{static assertion failed{{.*}}_ValueType may not be a reference.}}
- std::any_cast<int const&&>(&a2); // expected-note {{requested here}}
+ (void)std::any_cast<int const&&>(&a2); // expected-note {{requested here}}
}
diff --git a/libcxx/test/std/utilities/any/any.nonmembers/any.cast/void.verify.cpp b/libcxx/test/std/utilities/any/any.nonmembers/any.cast/void.verify.cpp
index 9530d63e07b0..d1ec42eaf10c 100644
--- a/libcxx/test/std/utilities/any/any.nonmembers/any.cast/void.verify.cpp
+++ b/libcxx/test/std/utilities/any/any.nonmembers/any.cast/void.verify.cpp
@@ -23,12 +23,12 @@ void test() {
const std::any ca = 1;
// expected-error-re@any:* {{static assertion failed{{.*}}_ValueType may not be void.}}
- std::any_cast<void>(&ca); // expected-note {{requested here}}
+ (void)std::any_cast<void>(&ca); // expected-note {{requested here}}
}
{
std::any a = 1;
// expected-error-re@any:* {{static assertion failed{{.*}}_ValueType may not be void.}}
- std::any_cast<void>(&a); // expected-note {{requested here}}
+ (void)std::any_cast<void>(&a); // expected-note {{requested here}}
}
}