Skip to content

Commit

Permalink
[libc++] [test] Rationalize the nodiscard tests for range adaptors.
Browse files Browse the repository at this point in the history
Reviewed as part of D115177.
  • Loading branch information
Arthur O'Dwyer committed Dec 7, 2021
1 parent bd0c0e5 commit b108cd7
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 12 deletions.
Expand Up @@ -16,10 +16,8 @@

void test() {
int range[] = {1, 2, 3};
auto f = [](int i) { return i; };

std::views::all(range); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}}
range | std::views::all; // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}}
std::views::transform(f) | std::views::all; // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}}
std::views::all | std::views::transform(f); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}}
std::views::all | std::views::all; // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}}
}
Expand Up @@ -10,8 +10,7 @@
// UNSUPPORTED: libcpp-no-concepts
// UNSUPPORTED: libcpp-has-no-incomplete-ranges

// Test the libc++ extension that std::views::common is marked as [[nodiscard]] to avoid
// the potential for user mistakenly thinking they're calling an algorithm.
// Test the libc++ extension that std::views::common is marked as [[nodiscard]].

#include <ranges>

Expand All @@ -20,4 +19,5 @@ void test() {

std::views::common(range); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}}
range | std::views::common; // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}}
std::views::all | std::views::common; // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}}
}
Expand Up @@ -9,10 +9,8 @@
// UNSUPPORTED: c++03, c++11, c++14, c++17
// UNSUPPORTED: libcpp-no-concepts
// UNSUPPORTED: libcpp-has-no-incomplete-ranges
// REQUIRES: libc++

// Test the libc++ extension that std::views::reverse is marked as [[nodiscard]] to avoid
// the potential for user mistakenly thinking they're calling an algorithm.
// Test the libc++ extension that std::views::reverse is marked as [[nodiscard]].

#include <ranges>

Expand All @@ -21,5 +19,5 @@ void test() {

std::views::reverse(range); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}}
range | std::views::reverse; // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}}
std::views::reverse | std::views::reverse; // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}}
std::views::all | std::views::reverse; // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}}
}
Expand Up @@ -10,8 +10,7 @@
// UNSUPPORTED: libcpp-no-concepts
// UNSUPPORTED: libcpp-has-no-incomplete-ranges

// Test the libc++ extension that std::views::transform is marked as [[nodiscard]] to avoid
// the potential for user mistakenly thinking they're calling an algorithm.
// Test the libc++ extension that std::views::transform is marked as [[nodiscard]].

#include <ranges>

Expand All @@ -22,5 +21,5 @@ void test() {
std::views::transform(f); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}}
std::views::transform(range, f); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}}
range | std::views::transform(f); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}}
std::views::transform(f) | std::views::transform(f); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}}
std::views::all | std::views::transform(f); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}}
}

0 comments on commit b108cd7

Please sign in to comment.