Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 18 additions & 9 deletions libc/config/gpu/nvptx/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,35 +6,44 @@
},
"printf": {
"LIBC_CONF_PRINTF_DISABLE_FLOAT": {
"value": true
"value": true,
"define": "LIBC_COPT_PRINTF_DISABLE_FLOAT"
},
"LIBC_CONF_PRINTF_DISABLE_INDEX_MODE": {
"value": true
"value": true,
"define": "LIBC_COPT_PRINTF_DISABLE_INDEX_MODE"
},
"LIBC_CONF_PRINTF_DISABLE_WRITE_INT": {
"value": true
"value": true,
"copt": "LIBC_COPT_PRINTF_DISABLE_WRITE_INT"
},
"LIBC_CONF_PRINTF_FLOAT_TO_STR_USE_MEGA_LONG_DOUBLE_TABLE": {
"value": false
"value": false,
"copt": "LIBC_COPT_FLOAT_TO_STR_USE_MEGA_LONG_DOUBLE_TABLE"
},
"LIBC_CONF_PRINTF_DISABLE_STRERROR": {
"value": true
"value": true,
"copt": "LIBC_COPT_PRINTF_DISABLE_STRERROR"
},
"LIBC_CONF_PRINTF_RUNTIME_DISPATCH": {
"value": false
"value": false,
"copt": "LIBC_COPT_PRINTF_RUNTIME_DISPATCH"
}
},
"scanf": {
"LIBC_CONF_SCANF_DISABLE_FLOAT": {
"value": true
"value": true,
"copt": "LIBC_COPT_SCANF_DISABLE_FLOAT"
},
"LIBC_CONF_SCANF_DISABLE_INDEX_MODE": {
"value": true
"value": true,
"copt": "LIBC_COPT_SCANF_DISABLE_INDEX_MODE"
}
},
"math": {
"LIBC_CONF_MATH_OPTIMIZATIONS": {
"value": "(LIBC_MATH_SKIP_ACCURATE_PASS | LIBC_MATH_SMALL_TABLES | LIBC_MATH_NO_ERRNO | LIBC_MATH_NO_EXCEPT)"
"value": "(LIBC_COPT_MATH_SKIP_ACCURATE_PASS | LIBC_COPT_MATH_SMALL_TABLES)",
"define": "LIBC_COPT_MATH_OPTIMIZATIONS"
}
}
}
4 changes: 2 additions & 2 deletions libcxx/include/__expected/expected.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ _LIBCPP_PUSH_MACROS
_LIBCPP_BEGIN_NAMESPACE_STD

template <class _Tp, class _Err>
class expected;
class [[nodiscard]] expected;

template <class _Tp>
struct __is_std_expected : false_type {};
Expand Down Expand Up @@ -1354,7 +1354,7 @@ class __expected_void_base {

template <class _Tp, class _Err>
requires is_void_v<_Tp>
class expected<_Tp, _Err> : private __expected_void_base<_Err> {
class [[nodiscard]] expected<_Tp, _Err> : private __expected_void_base<_Err> {
static_assert(__valid_std_unexpected<_Err>::value,
"[expected.void.general] A program that instantiates expected<T, E> with a E that is not a "
"valid argument for unexpected<E> is ill-formed");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
// U is a specialization of std::expected and std::is_same_v<U:error_type, E> is true

#include <expected>
#include <tuple>
#include <utility>

struct NotSameAsInt {};
Expand All @@ -51,7 +52,7 @@ void test() {
// U is not a specialization of std::expected
{
std::expected<int, int> f1(1);
f1.and_then(lval_return_not_std_expected); // expected-note{{in instantiation of function template specialization 'std::expected<int, int>::and_then<int (&)(int &)>' requested here}}
std::ignore = f1.and_then(lval_return_not_std_expected); // expected-note{{in instantiation of function template specialization 'std::expected<int, int>::and_then<int (&)(int &)>' requested here}}
// expected-error-re@*:* {{static assertion failed {{.*}}The result of f(value()) must be a specialization of std::expected}}
// expected-error-re@*:* {{{{.*}}cannot be used prior to '::' because it has no members}}
// expected-error-re@*:* {{no matching constructor for initialization of{{.*}}}}
Expand All @@ -60,7 +61,7 @@ void test() {
// !std::is_same_v<U:error_type, E>
{
std::expected<int, int> f1(1);
f1.and_then(lval_error_type_not_same_as_int); // expected-note{{in instantiation of function template specialization 'std::expected<int, int>::and_then<std::expected<int, NotSameAsInt> (&)(int &)>' requested here}}
std::ignore = f1.and_then(lval_error_type_not_same_as_int); // expected-note{{in instantiation of function template specialization 'std::expected<int, int>::and_then<std::expected<int, NotSameAsInt> (&)(int &)>' requested here}}
// expected-error-re@*:* {{static assertion failed {{.*}}The result of f(value()) must have the same error_type as this expected}}
}
}
Expand All @@ -70,7 +71,7 @@ void test() {
// U is not a specialization of std::expected
{
const std::expected<int, int> f1(1);
f1.and_then(clval_return_not_std_expected); // expected-note{{in instantiation of function template specialization 'std::expected<int, int>::and_then<int (&)(const int &)>' requested here}}
std::ignore = f1.and_then(clval_return_not_std_expected); // expected-note{{in instantiation of function template specialization 'std::expected<int, int>::and_then<int (&)(const int &)>' requested here}}
// expected-error-re@*:* {{static assertion failed {{.*}}The result of f(value()) must be a specialization of std::expected}}
// expected-error-re@*:* {{{{.*}}cannot be used prior to '::' because it has no members}}
// expected-error-re@*:* {{no matching constructor for initialization of{{.*}}}}
Expand All @@ -79,7 +80,7 @@ void test() {
// !std::is_same_v<U:error_type, E>
{
const std::expected<int, int> f1(1);
f1.and_then(clval_error_type_not_same_as_int); // expected-note{{in instantiation of function template specialization 'std::expected<int, int>::and_then<std::expected<int, NotSameAsInt> (&)(const int &)>' requested here}}
std::ignore = f1.and_then(clval_error_type_not_same_as_int); // expected-note{{in instantiation of function template specialization 'std::expected<int, int>::and_then<std::expected<int, NotSameAsInt> (&)(const int &)>' requested here}}
// expected-error-re@*:* {{static assertion failed {{.*}}The result of f(value()) must have the same error_type as this expected}}

}
Expand All @@ -90,7 +91,7 @@ void test() {
// U is not a specialization of std::expected
{
std::expected<int, int> f1(1);
std::move(f1).and_then(rval_return_not_std_expected); // expected-note{{in instantiation of function template specialization 'std::expected<int, int>::and_then<int (&)(int &&)>' requested here}}
std::ignore = std::move(f1).and_then(rval_return_not_std_expected); // expected-note{{in instantiation of function template specialization 'std::expected<int, int>::and_then<int (&)(int &&)>' requested here}}
// expected-error-re@*:* {{static assertion failed {{.*}}The result of f(std::move(value())) must be a specialization of std::expected}}
// expected-error-re@*:* {{{{.*}}cannot be used prior to '::' because it has no members}}
// expected-error-re@*:* {{no matching constructor for initialization of{{.*}}}}
Expand All @@ -99,7 +100,7 @@ void test() {
// !std::is_same_v<U:error_type, E>
{
std::expected<int, int> f1(1);
std::move(f1).and_then(rval_error_type_not_same_as_int); // expected-note{{in instantiation of function template specialization 'std::expected<int, int>::and_then<std::expected<int, NotSameAsInt> (&)(int &&)>' requested here}}
std::ignore = std::move(f1).and_then(rval_error_type_not_same_as_int); // expected-note{{in instantiation of function template specialization 'std::expected<int, int>::and_then<std::expected<int, NotSameAsInt> (&)(int &&)>' requested here}}
// expected-error-re@*:* {{static assertion failed {{.*}}The result of f(std::move(value())) must have the same error_type as this expected}}
}
}
Expand All @@ -109,7 +110,7 @@ void test() {
// U is not a specialization of std::expected
{
const std::expected<int, int> f1(1);
std::move(f1).and_then(crval_return_not_std_expected); // expected-note{{in instantiation of function template specialization 'std::expected<int, int>::and_then<int (&)(const int &&)>' requested here}}
std::ignore = std::move(f1).and_then(crval_return_not_std_expected); // expected-note{{in instantiation of function template specialization 'std::expected<int, int>::and_then<int (&)(const int &&)>' requested here}}
// expected-error-re@*:* {{static assertion failed {{.*}}The result of f(std::move(value())) must be a specialization of std::expected}}
// expected-error-re@*:* {{{{.*}}cannot be used prior to '::' because it has no members}}
// expected-error-re@*:* {{no matching constructor for initialization of{{.*}}}}
Expand All @@ -118,9 +119,16 @@ void test() {
// !std::is_same_v<U:error_type, E>
{
const std::expected<int, int> f1(1);
std::move(f1).and_then(crval_error_type_not_same_as_int); // expected-note{{in instantiation of function template specialization 'std::expected<int, int>::and_then<std::expected<int, NotSameAsInt> (&)(const int &&)>' requested here}}
std::ignore = std::move(f1).and_then(crval_error_type_not_same_as_int); // expected-note{{in instantiation of function template specialization 'std::expected<int, int>::and_then<std::expected<int, NotSameAsInt> (&)(const int &&)>' requested here}}
// expected-error-re@*:* {{static assertion failed {{.*}}The result of f(std::move(value())) must have the same error_type as this expected}}
}
}

// Test nodiscard
{
std::expected<int, int> f1(1);

f1.and_then([](const int&){ return std::expected<int, int>(1); }); // expected-warning{{ignoring return value of function declared with 'nodiscard' attribute}}
}
}
// clang-format on
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
//===----------------------------------------------------------------------===//
//
// 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++23

// <expected>

// Test that ignoring std::expected generates [[nodiscard]] warnings.

#include <expected>

std::expected<int, int> returns_expected() { return std::expected<int, int>(5); }

std::expected<void, int> returns_expected_void() { return std::expected<void, int>(); }

void test() {
returns_expected(); // expected-warning{{ignoring return value of function declared with 'nodiscard' attribute}}

returns_expected_void(); // expected-warning{{ignoring return value of function declared with 'nodiscard' attribute}}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
// G is a specialization of std::expected and std::is_same_v<G:value_type, T> is true

#include <expected>
#include <tuple>
#include <utility>

struct NotSameAsInt {};
Expand All @@ -51,7 +52,7 @@ void test() {
// G is not a specialization of std::expected
{
std::expected<int, int> f1(std::unexpected<int>(1));
f1.or_else(lval_return_not_std_expected); // expected-note{{in instantiation of function template specialization 'std::expected<int, int>::or_else<int (&)(int &)>' requested here}}
std::ignore = f1.or_else(lval_return_not_std_expected); // expected-note{{in instantiation of function template specialization 'std::expected<int, int>::or_else<int (&)(int &)>' requested here}}
// expected-error-re@*:* {{static assertion failed {{.*}}The result of f(error()) must be a specialization of std::expected}}
// expected-error-re@*:* {{{{.*}}cannot be used prior to '::' because it has no members}}
// expected-error-re@*:* {{no matching constructor for initialization of{{.*}}}}
Expand All @@ -60,7 +61,7 @@ void test() {
// !std::is_same_v<G:value_type, T>
{
std::expected<int, int> f1(std::unexpected<int>(1));
f1.or_else(lval_error_type_not_same_as_int); // expected-note{{in instantiation of function template specialization 'std::expected<int, int>::or_else<std::expected<NotSameAsInt, int> (&)(int &)>' requested here}}
std::ignore = f1.or_else(lval_error_type_not_same_as_int); // expected-note{{in instantiation of function template specialization 'std::expected<int, int>::or_else<std::expected<NotSameAsInt, int> (&)(int &)>' requested here}}
// expected-error-re@*:* {{static assertion failed {{.*}}The result of f(error()) must have the same value_type as this expected}}
}
}
Expand All @@ -70,7 +71,7 @@ void test() {
// G is not a specialization of std::expected
{
const std::expected<int, int> f1(std::unexpected<int>(1));
f1.or_else(clval_return_not_std_expected); // expected-note{{in instantiation of function template specialization 'std::expected<int, int>::or_else<int (&)(const int &)>' requested here}}
std::ignore = f1.or_else(clval_return_not_std_expected); // expected-note{{in instantiation of function template specialization 'std::expected<int, int>::or_else<int (&)(const int &)>' requested here}}
// expected-error-re@*:* {{static assertion failed {{.*}}The result of f(error()) must be a specialization of std::expected}}
// expected-error-re@*:* {{{{.*}}cannot be used prior to '::' because it has no members}}
// expected-error-re@*:* {{no matching constructor for initialization of{{.*}}}}
Expand All @@ -79,7 +80,7 @@ void test() {
// !std::is_same_v<G:value_type, T>
{
const std::expected<int, int> f1(std::unexpected<int>(1));
f1.or_else(clval_error_type_not_same_as_int); // expected-note{{in instantiation of function template specialization 'std::expected<int, int>::or_else<std::expected<NotSameAsInt, int> (&)(const int &)>' requested here}}
std::ignore = f1.or_else(clval_error_type_not_same_as_int); // expected-note{{in instantiation of function template specialization 'std::expected<int, int>::or_else<std::expected<NotSameAsInt, int> (&)(const int &)>' requested here}}
// expected-error-re@*:* {{static assertion failed {{.*}}The result of f(error()) must have the same value_type as this expected}}
}
}
Expand All @@ -89,7 +90,7 @@ void test() {
// G is not a specialization of std::expected
{
std::expected<int, int> f1(std::unexpected<int>(1));
std::move(f1).or_else(rval_return_not_std_expected); // expected-note{{in instantiation of function template specialization 'std::expected<int, int>::or_else<int (&)(int &&)>' requested here}}
std::ignore = std::move(f1).or_else(rval_return_not_std_expected); // expected-note{{in instantiation of function template specialization 'std::expected<int, int>::or_else<int (&)(int &&)>' requested here}}
// expected-error-re@*:* {{static assertion failed {{.*}}The result of f(std::move(error())) must be a specialization of std::expected}}
// expected-error-re@*:* {{{{.*}}cannot be used prior to '::' because it has no members}}
// expected-error-re@*:* {{no matching constructor for initialization of{{.*}}}}
Expand All @@ -98,7 +99,7 @@ void test() {
// !std::is_same_v<G:value_type, T>
{
std::expected<int, int> f1(std::unexpected<int>(1));
std::move(f1).or_else(rval_error_type_not_same_as_int); // expected-note{{in instantiation of function template specialization 'std::expected<int, int>::or_else<std::expected<NotSameAsInt, int> (&)(int &&)>' requested here}}
std::ignore = std::move(f1).or_else(rval_error_type_not_same_as_int); // expected-note{{in instantiation of function template specialization 'std::expected<int, int>::or_else<std::expected<NotSameAsInt, int> (&)(int &&)>' requested here}}
// expected-error-re@*:* {{static assertion failed {{.*}}The result of f(std::move(error())) must have the same value_type as this expected}}
}
}
Expand All @@ -108,7 +109,7 @@ void test() {
// G is not a specialization of std::expected
{
const std::expected<int, int> f1(std::unexpected<int>(1));
std::move(f1).or_else(crval_return_not_std_expected); // expected-note{{in instantiation of function template specialization 'std::expected<int, int>::or_else<int (&)(const int &&)>' requested here}}
std::ignore = std::move(f1).or_else(crval_return_not_std_expected); // expected-note{{in instantiation of function template specialization 'std::expected<int, int>::or_else<int (&)(const int &&)>' requested here}}
// expected-error-re@*:* {{static assertion failed {{.*}}The result of f(std::move(error())) must be a specialization of std::expected}}
// expected-error-re@*:* {{{{.*}}cannot be used prior to '::' because it has no members}}
// expected-error-re@*:* {{no matching constructor for initialization of{{.*}}}}
Expand All @@ -117,9 +118,17 @@ void test() {
// !std::is_same_v<G:value_type, T>
{
const std::expected<int, int> f1(std::unexpected<int>(1));
std::move(f1).or_else(crval_error_type_not_same_as_int); // expected-note{{in instantiation of function template specialization 'std::expected<int, int>::or_else<std::expected<NotSameAsInt, int> (&)(const int &&)>' requested here}}
std::ignore = std::move(f1).or_else(crval_error_type_not_same_as_int); // expected-note{{in instantiation of function template specialization 'std::expected<int, int>::or_else<std::expected<NotSameAsInt, int> (&)(const int &&)>' requested here}}
// expected-error-re@*:* {{static assertion failed {{.*}}The result of f(std::move(error())) must have the same value_type as this expected}}
}
}

// Test nodiscard
{
std::expected<int, int> f1(1);

f1.or_else([](const int&){ return std::expected<int, int>(1); }); // expected-warning{{ignoring return value of function declared with 'nodiscard' attribute}}

}
}
// clang-format on
Loading
Loading