Skip to content

Commit 575b46e

Browse files
committed
Test [[nodiscard]] extensions
1 parent 5b539d2 commit 575b46e

File tree

8 files changed

+240
-0
lines changed

8 files changed

+240
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
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, c++20
10+
11+
// <ranges>
12+
13+
// Test the libc++ extension that std::ranges::join_with_view::iterator<Const>::operator* is marked as [[nodiscard]].
14+
15+
#include <ranges>
16+
#include <utility>
17+
18+
void test() {
19+
char range[3][2] = {{'x', 'x'}, {'y', 'y'}, {'z', 'z'}};
20+
char pattern[2] = {',', ' '};
21+
22+
std::ranges::join_with_view view(range, pattern);
23+
24+
// clang-format off
25+
*view.begin(); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}}
26+
*std::as_const(view).begin(); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}}
27+
// clang-format on
28+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
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, c++20
10+
11+
// <ranges>
12+
13+
// Test the libc++ extension that std::ranges::join_with_view::iterator<Const>::operator== is marked as [[nodiscard]].
14+
15+
#include <ranges>
16+
#include <utility>
17+
18+
void test() {
19+
char16_t range[3][1] = {{u'x'}, {u'y'}, {u'z'}};
20+
char16_t pattern[1] = {u'-'};
21+
22+
std::ranges::join_with_view view(range, pattern);
23+
24+
// clang-format off
25+
(view.begin() == view.end()); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}}
26+
(std::as_const(view).begin() == view.end()); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}}
27+
(view.begin() == std::as_const(view).end()); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}}
28+
(std::as_const(view).begin() == std::as_const(view).end()); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}}
29+
// clang-format on
30+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
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, c++20
10+
11+
// <ranges>
12+
13+
// Test the libc++ extension that std::ranges::join_with_view::iterator<Const>::iter_move is marked as [[nodiscard]].
14+
15+
#include <ranges>
16+
#include <utility>
17+
18+
void test() {
19+
long range[2][1] = {{0L}, {2L}};
20+
long pattern[1] = {1L};
21+
22+
std::ranges::join_with_view view(range, pattern);
23+
24+
// clang-format off
25+
iter_move(view.begin()); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}}
26+
iter_move(std::as_const(view).begin()); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}}
27+
// clang-format on
28+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
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, c++20
10+
11+
// <ranges>
12+
13+
// Test the libc++ extension that std::views::join_with is marked as [[nodiscard]].
14+
15+
#include <ranges>
16+
17+
void test() {
18+
int range[3][3] = {{1, 2, 3}, {4, 5, 6}, {7, 8, 9}};
19+
int pattern_base[2] = {-1, -1};
20+
auto pattern = std::views::all(pattern_base);
21+
22+
// clang-format off
23+
std::views::join_with(pattern); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}}
24+
std::views::join_with(range, pattern); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}}
25+
range | std::views::join_with(pattern); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}}
26+
std::views::reverse | std::views::join_with(pattern); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}}
27+
28+
std::views::join_with(0); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}}
29+
std::views::join_with(range, 0); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}}
30+
range | std::views::join_with(0); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}}
31+
std::views::reverse | std::views::join_with(0); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}}
32+
// clang-format on
33+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
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, c++20
10+
11+
// <ranges>
12+
13+
// Test the libc++ extension that std::ranges::join_with_view::sentinel<Const>::operator== is marked as [[nodiscard]].
14+
15+
#include <array>
16+
#include <ranges>
17+
#include <utility>
18+
19+
#include "test_iterators.h"
20+
#include "test_range.h"
21+
22+
void test() {
23+
std::array<test_range<cpp20_input_iterator>, 0> range;
24+
std::array<int, 0> pattern;
25+
26+
std::ranges::join_with_view view(range, pattern);
27+
static_assert(!std::ranges::common_range<decltype(view)>);
28+
29+
// clang-format off
30+
(view.begin() == view.end()); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}}
31+
(std::as_const(view).begin() == view.end()); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}}
32+
(view.begin() == std::as_const(view).end()); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}}
33+
(std::as_const(view).begin() == std::as_const(view).end()); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}}
34+
// clang-format on
35+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
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, c++20
10+
11+
// <ranges>
12+
13+
// Test the libc++ extension that std::ranges::join_with_view::base is marked as [[nodiscard]].
14+
15+
#include <ranges>
16+
#include <utility>
17+
18+
void test() {
19+
int range[3][3] = {{1, 2, 3}, {4, 5, 6}, {7, 8, 9}};
20+
int pattern[2] = {-1, -1};
21+
22+
std::ranges::join_with_view view(range, pattern);
23+
24+
// clang-format off
25+
view.base(); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}}
26+
std::as_const(view).base(); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}}
27+
std::move(std::as_const(view)).base(); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}}
28+
std::move(view).base(); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}}
29+
// clang-format on
30+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
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, c++20
10+
11+
// <ranges>
12+
13+
// Test the libc++ extension that std::ranges::join_with_view::begin is marked as [[nodiscard]].
14+
15+
#include <ranges>
16+
#include <utility>
17+
18+
void test() {
19+
int range[3][2] = {{1, 3}, {4, 6}, {7, 9}};
20+
int pattern[1] = {-2};
21+
22+
std::ranges::join_with_view view(range, pattern);
23+
24+
// clang-format off
25+
view.begin(); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}}
26+
std::as_const(view).begin(); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}}
27+
// clang-format on
28+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
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, c++20
10+
11+
// <ranges>
12+
13+
// Test the libc++ extension that std::ranges::join_with_view::end is marked as [[nodiscard]].
14+
15+
#include <ranges>
16+
#include <utility>
17+
18+
void test() {
19+
int range[3][2] = {{1, 2}, {4, 5}, {7, 8}};
20+
int pattern[1] = {-3};
21+
22+
std::ranges::join_with_view view(range, pattern);
23+
24+
// clang-format off
25+
view.end(); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}}
26+
std::as_const(view).end(); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}}
27+
// clang-format on
28+
}

0 commit comments

Comments
 (0)