Skip to content

Commit 5943a16

Browse files
committed
[libcxx] unit test for verifing nodiscard for std::expected
1 parent 5ef0eb9 commit 5943a16

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
//===----------------------------------------------------------------------===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
9+
// UNSUPPORTED: c++03, c++11, c++14, c++17
10+
11+
// <expected>
12+
13+
// Test that std::expected generates [[nodiscard]] warnings
14+
15+
#include <expected>
16+
17+
std::expected<int, int> returns_expected() {
18+
return std::expected<int, int>(5);
19+
}
20+
21+
std::expected<void, int> returns_expected_void() {
22+
return std::expected<void, int>();
23+
}
24+
25+
void test() {
26+
// expected-warning@+1 {{ignoring return value of function declared with 'nodiscard' attribute}}
27+
returns_expected();
28+
29+
// expected-warning@+1 {{ignoring return value of function declared with 'nodiscard' attribute}}
30+
returns_expected_void();
31+
}

0 commit comments

Comments
 (0)