Skip to content
Closed
Show file tree
Hide file tree
Changes from 2 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
2 changes: 1 addition & 1 deletion libcxx/include/__cxx03/__expected/expected.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ _LIBCPP_PUSH_MACROS
_LIBCPP_BEGIN_NAMESPACE_STD

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

template <class _Tp>
struct __is_std_expected : false_type {};
Expand Down
2 changes: 1 addition & 1 deletion 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
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
//===----------------------------------------------------------------------===//
//
// 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
//
//===----------------------------------------------------------------------===//

// UNSUPPORTED: c++03, c++11, c++14, c++17

// <expected>

// Test that 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() {
// expected-warning@+1 {{ignoring return value of function declared with 'nodiscard' attribute}}
returns_expected();

// expected-warning@+1 {{ignoring return value of function declared with 'nodiscard' attribute}}
returns_expected_void();
}