[libcxx-commits] [libcxx] [libc++][any] Applied `[[nodiscard]]` (PR #168826)
Hristo Hristov via libcxx-commits
libcxx-commits at lists.llvm.org
Thu Nov 20 09:00:59 PST 2025
https://github.com/H-G-Hristov updated https://github.com/llvm/llvm-project/pull/168826
>From 7910416b106183e2aec9c87cbaacad0e6d22cb92 Mon Sep 17 00:00:00 2001
From: Hristo Hristov <hghristov.rmm at gmail.com>
Date: Thu, 20 Nov 2025 07:05:59 +0200
Subject: [PATCH 1/3] [libc++][any] Applied `[[nodiscard]]`
`[[nodiscard]]` should be applied to functions where discarding the return value is most likely a correctness issue.
- https://libcxx.llvm.org/CodingGuidelines.html#apply-nodiscard-where-relevant
---
libcxx/include/any | 18 ++++----
.../libcxx/utilities/any/nodiscard.verify.cpp | 45 +++++++++++++++++++
..._request_invalid_value_category.verify.cpp | 21 +++------
.../any.cast/const_correctness.verify.cpp | 8 ++--
.../not_copy_constructible.verify.cpp | 8 ++--
.../any.cast/reference_types.verify.cpp | 21 ++++-----
.../any.nonmembers/any.cast/void.verify.cpp | 4 +-
7 files changed, 79 insertions(+), 46 deletions(-)
create mode 100644 libcxx/test/libcxx/utilities/any/nodiscard.verify.cpp
diff --git a/libcxx/include/any b/libcxx/include/any
index b3e5b8748df4c..5c779e397c9ea 100644
--- a/libcxx/include/any
+++ b/libcxx/include/any
@@ -262,10 +262,10 @@ public:
_LIBCPP_HIDE_FROM_ABI void swap(any& __rhs) _NOEXCEPT;
// 6.3.4 any observers
- _LIBCPP_HIDE_FROM_ABI bool has_value() const _NOEXCEPT { return __h_ != nullptr; }
+ [[nodiscard]] _LIBCPP_HIDE_FROM_ABI bool has_value() const _NOEXCEPT { return __h_ != nullptr; }
# if _LIBCPP_HAS_RTTI
- _LIBCPP_HIDE_FROM_ABI const type_info& type() const _NOEXCEPT {
+ [[nodiscard]] _LIBCPP_HIDE_FROM_ABI const type_info& type() const _NOEXCEPT {
if (__h_) {
return *static_cast<type_info const*>(this->__call(_Action::_TypeInfo));
} else {
@@ -492,17 +492,17 @@ inline _LIBCPP_HIDE_FROM_ABI void any::swap(any& __rhs) _NOEXCEPT {
inline _LIBCPP_HIDE_FROM_ABI void swap(any& __lhs, any& __rhs) _NOEXCEPT { __lhs.swap(__rhs); }
template <class _Tp, class... _Args>
-inline _LIBCPP_HIDE_FROM_ABI any make_any(_Args&&... __args) {
+[[nodiscard]] inline _LIBCPP_HIDE_FROM_ABI any make_any(_Args&&... __args) {
return any(in_place_type<_Tp>, std::forward<_Args>(__args)...);
}
template <class _Tp, class _Up, class... _Args>
-inline _LIBCPP_HIDE_FROM_ABI any make_any(initializer_list<_Up> __il, _Args&&... __args) {
+[[nodiscard]] inline _LIBCPP_HIDE_FROM_ABI any make_any(initializer_list<_Up> __il, _Args&&... __args) {
return any(in_place_type<_Tp>, __il, std::forward<_Args>(__args)...);
}
template <class _ValueType>
-inline _LIBCPP_HIDE_FROM_ABI _ValueType any_cast(any const& __v) {
+[[nodiscard]] inline _LIBCPP_HIDE_FROM_ABI _ValueType any_cast(any const& __v) {
using _RawValueType = __remove_cvref_t<_ValueType>;
static_assert(is_constructible<_ValueType, _RawValueType const&>::value,
"ValueType is required to be a const lvalue reference "
@@ -514,7 +514,7 @@ inline _LIBCPP_HIDE_FROM_ABI _ValueType any_cast(any const& __v) {
}
template <class _ValueType>
-inline _LIBCPP_HIDE_FROM_ABI _ValueType any_cast(any& __v) {
+[[nodiscard]] inline _LIBCPP_HIDE_FROM_ABI _ValueType any_cast(any& __v) {
using _RawValueType = __remove_cvref_t<_ValueType>;
static_assert(is_constructible<_ValueType, _RawValueType&>::value,
"ValueType is required to be an lvalue reference "
@@ -526,7 +526,7 @@ inline _LIBCPP_HIDE_FROM_ABI _ValueType any_cast(any& __v) {
}
template <class _ValueType>
-inline _LIBCPP_HIDE_FROM_ABI _ValueType any_cast(any&& __v) {
+[[nodiscard]] inline _LIBCPP_HIDE_FROM_ABI _ValueType any_cast(any&& __v) {
using _RawValueType = __remove_cvref_t<_ValueType>;
static_assert(is_constructible<_ValueType, _RawValueType>::value,
"ValueType is required to be an rvalue reference "
@@ -538,7 +538,7 @@ inline _LIBCPP_HIDE_FROM_ABI _ValueType any_cast(any&& __v) {
}
template <class _ValueType>
-inline _LIBCPP_HIDE_FROM_ABI add_pointer_t<add_const_t<_ValueType>> any_cast(any const* __any) _NOEXCEPT {
+[[nodiscard]] inline _LIBCPP_HIDE_FROM_ABI add_pointer_t<add_const_t<_ValueType>> any_cast(any const* __any) _NOEXCEPT {
static_assert(!is_void_v<_ValueType>, "_ValueType may not be void.");
static_assert(!is_reference<_ValueType>::value, "_ValueType may not be a reference.");
return std::any_cast<_ValueType>(const_cast<any*>(__any));
@@ -555,7 +555,7 @@ inline _LIBCPP_HIDE_FROM_ABI _RetType __pointer_or_func_cast(void*, /*IsFunction
}
template <class _ValueType>
-_LIBCPP_HIDE_FROM_ABI add_pointer_t<_ValueType> any_cast(any* __any) _NOEXCEPT {
+[[nodiscard]] _LIBCPP_HIDE_FROM_ABI add_pointer_t<_ValueType> any_cast(any* __any) _NOEXCEPT {
using __any_imp::_Action;
static_assert(!is_void_v<_ValueType>, "_ValueType may not be void.");
static_assert(!is_reference<_ValueType>::value, "_ValueType may not be a reference.");
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 0000000000000..13a67bd3c3044
--- /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 at +1 {{ignoring return value of function declared with 'nodiscard' attribute}}
+ a.has_value();
+#if !defined(TEST_HAS_NO_RTTI)
+ // expected-warning at +1 {{ignoring return value of function declared with 'nodiscard' attribute}}
+ a.type();
+#endif
+
+ // expected-warning at +1 {{ignoring return value of function declared with 'nodiscard' attribute}}
+ std::make_any<int>(82);
+ // expected-warning at +1 {{ignoring return value of function declared with 'nodiscard' attribute}}
+ std::make_any<std::vector<int>>({94, 82, 50});
+
+ // expected-warning at +1 {{ignoring return value of function declared with 'nodiscard' attribute}}
+ std::any_cast<const int&>(std::as_const(a));
+ // expected-warning at +1 {{ignoring return value of function declared with 'nodiscard' attribute}}
+ std::any_cast<int&>(a);
+ // expected-warning at +1 {{ignoring return value of function declared with 'nodiscard' attribute}}
+ std::any_cast<int&&>(std::move(a));
+
+ // expected-warning at +1 {{ignoring return value of function declared with 'nodiscard' attribute}}
+ std::any_cast<int*>(&a);
+ // expected-warning at +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 34f785fdff6bc..bb0fa1f4d9aff 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
@@ -24,23 +24,23 @@ void test_const_lvalue_cast_request_non_const_lvalue()
const std::any a;
// expected-error-re at any:* {{static assertion failed{{.*}}ValueType is required to be a const lvalue reference or a CopyConstructible type}}
// expected-error at 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 at any:* {{static assertion failed{{.*}}ValueType is required to be a const lvalue reference or a CopyConstructible type}}
// expected-error at 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 at 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 at 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()
@@ -48,18 +48,9 @@ void test_rvalue_any_cast_request_lvalue()
std::any a;
// expected-error-re at any:* {{static assertion failed{{.*}}ValueType is required to be an rvalue reference or a CopyConstructible type}}
// expected-error at 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 at any:* {{static assertion failed{{.*}}ValueType is required to be an rvalue reference or a CopyConstructible type}}
// expected-error at any:* {{non-const lvalue reference to type 'int' cannot bind to a temporary}}
- std::any_cast<int&>(42);
-}
-
-int main(int, char**)
-{
- test_const_lvalue_cast_request_non_const_lvalue();
- test_lvalue_any_cast_request_rvalue();
- test_rvalue_any_cast_request_lvalue();
-
- return 0;
+ (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 1830626d7f410..434093ab780fd 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 f() {
std::any a;
// expected-error-re at 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 at 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 at 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 at 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 3b9aac581a083..f489db1213ef2 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 f() {
std::any a;
// expected-error-re at 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 at 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 at 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 0a13fdf0c6d80..4fec3e6ee758d 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
@@ -18,35 +18,32 @@
#include <any>
-int main(int, char**)
-{
+void test() {
std::any a = 1;
// expected-error-re at 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 at 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 at 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 at 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 at 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 at 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 at 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 at any:* 1 {{static assertion failed{{.*}}_ValueType may not be a reference.}}
- std::any_cast<int const &&>(&a2); // expected-note {{requested here}}
-
- return 0;
+ (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 9530d63e07b0a..d1ec42eaf10c2 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 at 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 at 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}}
}
}
>From da2b7003075fc302f57b80d78137d69b440bd700 Mon Sep 17 00:00:00 2001
From: Hristo Hristov <hghristov.rmm at gmail.com>
Date: Thu, 20 Nov 2025 18:23:15 +0200
Subject: [PATCH 2/3] Formatting
---
...ny_cast_request_invalid_value_category.verify.cpp | 6 +++---
.../any.cast/const_correctness.verify.cpp | 8 ++++----
.../any.cast/not_copy_constructible.verify.cpp | 4 ++--
.../any.cast/reference_types.verify.cpp | 12 ++++++------
4 files changed, 15 insertions(+), 15 deletions(-)
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 bb0fa1f4d9aff..c0d94abd3f5ba 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
@@ -24,7 +24,7 @@ void test_const_lvalue_cast_request_non_const_lvalue()
const std::any a;
// expected-error-re at any:* {{static assertion failed{{.*}}ValueType is required to be a const lvalue reference or a CopyConstructible type}}
// expected-error at any:* {{drops 'const' qualifier}}
- (void)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 at any:* {{static assertion failed{{.*}}ValueType is required to be a const lvalue reference or a CopyConstructible type}}
@@ -36,7 +36,7 @@ void test_lvalue_any_cast_request_rvalue()
{
std::any a;
// expected-error-re at any:* {{static assertion failed{{.*}}ValueType is required to be an lvalue reference or a CopyConstructible type}}
- (void)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 at any:* {{static assertion failed{{.*}}ValueType is required to be an lvalue reference or a CopyConstructible type}}
@@ -48,7 +48,7 @@ void test_rvalue_any_cast_request_lvalue()
std::any a;
// expected-error-re at any:* {{static assertion failed{{.*}}ValueType is required to be an rvalue reference or a CopyConstructible type}}
// expected-error at any:* {{non-const lvalue reference to type 'TestType' cannot bind to a temporary}}
- (void)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 at any:* {{static assertion failed{{.*}}ValueType is required to be an rvalue reference or a CopyConstructible type}}
// expected-error at any:* {{non-const lvalue reference to type 'int' cannot bind to a temporary}}
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 434093ab780fd..85f5e872a3b97 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 f() {
std::any a;
// expected-error-re at any:* {{static assertion failed{{.*}}ValueType is required to be a const lvalue reference or a CopyConstructible type}}
- (void)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 at any:* {{static assertion failed{{.*}}ValueType is required to be a const lvalue reference or a CopyConstructible type}}
- (void)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 at any:* {{static assertion failed{{.*}}ValueType is required to be a const lvalue reference or a CopyConstructible type}}
- (void)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 at any:* {{static assertion failed{{.*}}ValueType is required to be a const lvalue reference or a CopyConstructible type}}
- (void)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 f489db1213ef2..e17424a7e6739 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
@@ -50,8 +50,8 @@ void f() {
// expected-error-re at any:* {{static assertion failed{{.*}}ValueType is required to be a const lvalue reference or a CopyConstructible type}}
(void)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 &&>(a)); // OK
+ (void)std::any_cast<no_copy>(static_cast<std::any&&>(a)); // OK
// expected-error-re at any:* {{static assertion failed{{.*}}ValueType is required to be an rvalue reference or a CopyConstructible type}}
- (void)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 4fec3e6ee758d..a776abdf4ff87 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,13 +22,13 @@ void test() {
std::any a = 1;
// expected-error-re at any:* 1 {{static assertion failed{{.*}}_ValueType may not be a reference.}}
- (void)std::any_cast<int &>(&a); // expected-note {{requested here}}
+ (void)std::any_cast<int&>(&a); // expected-note {{requested here}}
// expected-error-re at any:* 1 {{static assertion failed{{.*}}_ValueType may not be a reference.}}
- (void)std::any_cast<int &&>(&a); // expected-note {{requested here}}
+ (void)std::any_cast<int&&>(&a); // expected-note {{requested here}}
// expected-error-re at any:* 1 {{static assertion failed{{.*}}_ValueType may not be a reference.}}
- (void)std::any_cast<int const &>(&a); // expected-note {{requested here}}
+ (void)std::any_cast<int const&>(&a); // expected-note {{requested here}}
// expected-error-re at any:* 1 {{static assertion failed{{.*}}_ValueType may not be a reference.}}
(void)std::any_cast<int const&&>(&a); // expected-note {{requested here}}
@@ -39,11 +39,11 @@ void test() {
(void)std::any_cast<int &>(&a2); // expected-note {{requested here}}
// expected-error-re at any:* 1 {{static assertion failed{{.*}}_ValueType may not be a reference.}}
- (void)std::any_cast<int &&>(&a2); // expected-note {{requested here}}
+ (void)std::any_cast<int&&>(&a2); // expected-note {{requested here}}
// expected-error-re at any:* 1 {{static assertion failed{{.*}}_ValueType may not be a reference.}}
- (void)std::any_cast<int const &>(&a2); // expected-note {{requested here}}
+ (void)std::any_cast<int const&>(&a2); // expected-note {{requested here}}
// expected-error-re at any:* 1 {{static assertion failed{{.*}}_ValueType may not be a reference.}}
- (void)std::any_cast<int const &&>(&a2); // expected-note {{requested here}}
+ (void)std::any_cast<int const&&>(&a2); // expected-note {{requested here}}
}
>From 6890692709008265ef2ead244d2878c6985fa970 Mon Sep 17 00:00:00 2001
From: Hristo Hristov <hghristov.rmm at gmail.com>
Date: Thu, 20 Nov 2025 19:00:38 +0200
Subject: [PATCH 3/3] Fix formatting
---
..._request_invalid_value_category.verify.cpp | 53 +++++++++----------
.../any.cast/const_correctness.verify.cpp | 18 +++----
.../not_copy_constructible.verify.cpp | 28 +++++-----
.../any.cast/reference_types.verify.cpp | 36 ++++++-------
4 files changed, 66 insertions(+), 69 deletions(-)
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 c0d94abd3f5ba..55e9923eab850 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
@@ -19,38 +19,35 @@
struct TestType {};
-void test_const_lvalue_cast_request_non_const_lvalue()
-{
- const std::any a;
- // expected-error-re at any:* {{static assertion failed{{.*}}ValueType is required to be a const lvalue reference or a CopyConstructible type}}
- // expected-error at any:* {{drops 'const' qualifier}}
- (void)std::any_cast<TestType&>(a); // expected-note {{requested here}}
-
- const std::any a2(42);
- // expected-error-re at any:* {{static assertion failed{{.*}}ValueType is required to be a const lvalue reference or a CopyConstructible type}}
- // expected-error at any:* {{drops 'const' qualifier}}
- (void)std::any_cast<int&>(a2); // expected-note {{requested here}}
+void test_const_lvalue_cast_request_non_const_lvalue() {
+ const std::any a;
+ // expected-error-re at any:* {{static assertion failed{{.*}}ValueType is required to be a const lvalue reference or a CopyConstructible type}}
+ // expected-error at any:* {{drops 'const' qualifier}}
+ (void)std::any_cast<TestType&>(a); // expected-note {{requested here}}
+
+ const std::any a2(42);
+ // expected-error-re at any:* {{static assertion failed{{.*}}ValueType is required to be a const lvalue reference or a CopyConstructible type}}
+ // expected-error at any:* {{drops 'const' qualifier}}
+ (void)std::any_cast<int&>(a2); // expected-note {{requested here}}
}
-void test_lvalue_any_cast_request_rvalue()
-{
- std::any a;
- // expected-error-re at any:* {{static assertion failed{{.*}}ValueType is required to be an lvalue reference or a CopyConstructible type}}
- (void)std::any_cast<TestType&&>(a); // expected-note {{requested here}}
+void test_lvalue_any_cast_request_rvalue() {
+ std::any a;
+ // expected-error-re at any:* {{static assertion failed{{.*}}ValueType is required to be an lvalue reference or a CopyConstructible type}}
+ (void)std::any_cast<TestType&&>(a); // expected-note {{requested here}}
- std::any a2(42);
- // expected-error-re at any:* {{static assertion failed{{.*}}ValueType is required to be an lvalue reference or a CopyConstructible type}}
- (void)std::any_cast<int&&>(a2); // expected-note {{requested here}}
+ std::any a2(42);
+ // expected-error-re at any:* {{static assertion failed{{.*}}ValueType is required to be an lvalue reference or a CopyConstructible type}}
+ (void)std::any_cast<int&&>(a2); // expected-note {{requested here}}
}
-void test_rvalue_any_cast_request_lvalue()
-{
- std::any a;
- // expected-error-re at any:* {{static assertion failed{{.*}}ValueType is required to be an rvalue reference or a CopyConstructible type}}
- // expected-error at any:* {{non-const lvalue reference to type 'TestType' cannot bind to a temporary}}
- (void)std::any_cast<TestType&>(std::move(a)); // expected-note {{requested here}}
+void test_rvalue_any_cast_request_lvalue() {
+ std::any a;
+ // expected-error-re at any:* {{static assertion failed{{.*}}ValueType is required to be an rvalue reference or a CopyConstructible type}}
+ // expected-error at any:* {{non-const lvalue reference to type 'TestType' cannot bind to a temporary}}
+ (void)std::any_cast<TestType&>(std::move(a)); // expected-note {{requested here}}
- // expected-error-re at any:* {{static assertion failed{{.*}}ValueType is required to be an rvalue reference or a CopyConstructible type}}
- // expected-error at any:* {{non-const lvalue reference to type 'int' cannot bind to a temporary}}
- (void)std::any_cast<int&>(42);
+ // expected-error-re at any:* {{static assertion failed{{.*}}ValueType is required to be an rvalue reference or a CopyConstructible type}}
+ // expected-error at any:* {{non-const lvalue reference to type 'int' cannot bind to a temporary}}
+ (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 85f5e872a3b97..39ef0651cd270 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
@@ -28,17 +28,17 @@ struct TestType {};
struct TestType2 {};
void f() {
- std::any a;
+ std::any a;
- // expected-error-re at any:* {{static assertion failed{{.*}}ValueType is required to be a const lvalue reference or a CopyConstructible type}}
- (void)std::any_cast<TestType&>(static_cast<std::any const&>(a)); // expected-note {{requested here}}
+ // expected-error-re at any:* {{static assertion failed{{.*}}ValueType is required to be a const lvalue reference or a CopyConstructible type}}
+ (void)std::any_cast<TestType&>(static_cast<std::any const&>(a)); // expected-note {{requested here}}
- // expected-error-re at any:* {{static assertion failed{{.*}}ValueType is required to be a const lvalue reference or a CopyConstructible type}}
- (void)std::any_cast<TestType&&>(static_cast<std::any const&>(a)); // expected-note {{requested here}}
+ // expected-error-re at any:* {{static assertion failed{{.*}}ValueType is required to be a const lvalue reference or a CopyConstructible type}}
+ (void)std::any_cast<TestType&&>(static_cast<std::any const&>(a)); // expected-note {{requested here}}
- // expected-error-re at any:* {{static assertion failed{{.*}}ValueType is required to be a const lvalue reference or a CopyConstructible type}}
- (void)std::any_cast<TestType2&>(static_cast<std::any const&&>(a)); // expected-note {{requested here}}
+ // expected-error-re at any:* {{static assertion failed{{.*}}ValueType is required to be a const lvalue reference or a CopyConstructible type}}
+ (void)std::any_cast<TestType2&>(static_cast<std::any const&&>(a)); // expected-note {{requested here}}
- // expected-error-re at any:* {{static assertion failed{{.*}}ValueType is required to be a const lvalue reference or a CopyConstructible type}}
- (void)std::any_cast<TestType2&&>(static_cast<std::any const&&>(a)); // expected-note {{requested here}}
+ // expected-error-re at any:* {{static assertion failed{{.*}}ValueType is required to be a const lvalue reference or a CopyConstructible type}}
+ (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 e17424a7e6739..597727c9a4438 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
@@ -31,27 +31,27 @@
#include <any>
struct no_copy {
- no_copy() {}
- no_copy(no_copy &&) {}
- no_copy(no_copy const &) = delete;
+ no_copy() {}
+ no_copy(no_copy&&) {}
+ no_copy(no_copy const&) = delete;
};
struct no_move {
- no_move() {}
- no_move(no_move&&) = delete;
- no_move(no_move const&) {}
+ no_move() {}
+ no_move(no_move&&) = delete;
+ no_move(no_move const&) {}
};
void f() {
- std::any a;
- // expected-error-re at any:* {{static assertion failed{{.*}}ValueType is required to be an lvalue reference or a CopyConstructible type}}
- (void)std::any_cast<no_copy>(static_cast<std::any&>(a)); // expected-note {{requested here}}
+ std::any a;
+ // expected-error-re at any:* {{static assertion failed{{.*}}ValueType is required to be an lvalue reference or a CopyConstructible type}}
+ (void)std::any_cast<no_copy>(static_cast<std::any&>(a)); // expected-note {{requested here}}
- // expected-error-re at any:* {{static assertion failed{{.*}}ValueType is required to be a const lvalue reference or a CopyConstructible type}}
- (void)std::any_cast<no_copy>(static_cast<std::any const&>(a)); // expected-note {{requested here}}
+ // expected-error-re at any:* {{static assertion failed{{.*}}ValueType is required to be a const lvalue reference or a CopyConstructible type}}
+ (void)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&&>(a)); // OK
+ (void)std::any_cast<no_copy>(static_cast<std::any&&>(a)); // OK
- // expected-error-re at any:* {{static assertion failed{{.*}}ValueType is required to be an rvalue reference or a CopyConstructible type}}
- (void)std::any_cast<no_move>(static_cast<std::any&&>(a));
+ // expected-error-re at any:* {{static assertion failed{{.*}}ValueType is required to be an rvalue reference or a CopyConstructible type}}
+ (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 a776abdf4ff87..d634f73291e0e 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
@@ -19,31 +19,31 @@
#include <any>
void test() {
- std::any a = 1;
+ std::any a = 1;
- // expected-error-re at any:* 1 {{static assertion failed{{.*}}_ValueType may not be a reference.}}
- (void)std::any_cast<int&>(&a); // expected-note {{requested here}}
+ // expected-error-re at any:* 1 {{static assertion failed{{.*}}_ValueType may not be a reference.}}
+ (void)std::any_cast<int&>(&a); // expected-note {{requested here}}
- // expected-error-re at any:* 1 {{static assertion failed{{.*}}_ValueType may not be a reference.}}
- (void)std::any_cast<int&&>(&a); // expected-note {{requested here}}
+ // expected-error-re at any:* 1 {{static assertion failed{{.*}}_ValueType may not be a reference.}}
+ (void)std::any_cast<int&&>(&a); // expected-note {{requested here}}
- // expected-error-re at any:* 1 {{static assertion failed{{.*}}_ValueType may not be a reference.}}
- (void)std::any_cast<int const&>(&a); // expected-note {{requested here}}
+ // expected-error-re at any:* 1 {{static assertion failed{{.*}}_ValueType may not be a reference.}}
+ (void)std::any_cast<int const&>(&a); // expected-note {{requested here}}
- // expected-error-re at any:* 1 {{static assertion failed{{.*}}_ValueType may not be a reference.}}
- (void)std::any_cast<int const&&>(&a); // expected-note {{requested here}}
+ // expected-error-re at any:* 1 {{static assertion failed{{.*}}_ValueType may not be a reference.}}
+ (void)std::any_cast<int const&&>(&a); // expected-note {{requested here}}
- const std::any& a2 = a;
+ const std::any& a2 = a;
- // expected-error-re at any:* 1 {{static assertion failed{{.*}}_ValueType may not be a reference.}}
- (void)std::any_cast<int &>(&a2); // expected-note {{requested here}}
+ // expected-error-re at any:* 1 {{static assertion failed{{.*}}_ValueType may not be a reference.}}
+ (void)std::any_cast<int&>(&a2); // expected-note {{requested here}}
- // expected-error-re at any:* 1 {{static assertion failed{{.*}}_ValueType may not be a reference.}}
- (void)std::any_cast<int&&>(&a2); // expected-note {{requested here}}
+ // expected-error-re at any:* 1 {{static assertion failed{{.*}}_ValueType may not be a reference.}}
+ (void)std::any_cast<int&&>(&a2); // expected-note {{requested here}}
- // expected-error-re at any:* 1 {{static assertion failed{{.*}}_ValueType may not be a reference.}}
- (void)std::any_cast<int const&>(&a2); // expected-note {{requested here}}
+ // expected-error-re at any:* 1 {{static assertion failed{{.*}}_ValueType may not be a reference.}}
+ (void)std::any_cast<int const&>(&a2); // expected-note {{requested here}}
- // expected-error-re at any:* 1 {{static assertion failed{{.*}}_ValueType may not be a reference.}}
- (void)std::any_cast<int const&&>(&a2); // expected-note {{requested here}}
+ // expected-error-re at any:* 1 {{static assertion failed{{.*}}_ValueType may not be a reference.}}
+ (void)std::any_cast<int const&&>(&a2); // expected-note {{requested here}}
}
More information about the libcxx-commits
mailing list