|
| 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 | +// Check that functions are marked [[nodiscard]] |
| 10 | + |
| 11 | +#include <stdexcept> |
| 12 | +#include <system_error> |
| 13 | + |
| 14 | +void test() { |
| 15 | + { // <stdexcept> |
| 16 | + std::logic_error le("logic error"); |
| 17 | + le.what(); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}} |
| 18 | + |
| 19 | + std::runtime_error re("runtime error"); |
| 20 | + re.what(); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}} |
| 21 | + |
| 22 | + std::domain_error de("domain error"); |
| 23 | + de.what(); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}} |
| 24 | + |
| 25 | + std::invalid_argument ia("invalid argument"); |
| 26 | + ia.what(); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}} |
| 27 | + |
| 28 | + std::length_error lerr("length error"); |
| 29 | + lerr.what(); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}} |
| 30 | + |
| 31 | + std::out_of_range oor("out of range"); |
| 32 | + oor.what(); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}} |
| 33 | + |
| 34 | + std::range_error rerr("range error"); |
| 35 | + rerr.what(); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}} |
| 36 | + |
| 37 | + std::overflow_error oferr("overflow error"); |
| 38 | + oferr.what(); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}} |
| 39 | + |
| 40 | + std::underflow_error uferr("underflow error"); |
| 41 | + uferr.what(); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}} |
| 42 | + } |
| 43 | + { // <system_error> |
| 44 | + { |
| 45 | + // expected-warning@+1 {{ignoring return value of function declared with 'nodiscard' attribute}} |
| 46 | + std::generic_category(); |
| 47 | + |
| 48 | + const std::error_category& ec = std::generic_category(); |
| 49 | + |
| 50 | + // expected-warning@+1 {{ignoring return value of function declared with 'nodiscard' attribute}} |
| 51 | + ec.name(); |
| 52 | + // expected-warning@+1 {{ignoring return value of function declared with 'nodiscard' attribute}} |
| 53 | + ec.default_error_condition(94); |
| 54 | + // expected-warning@+1 {{ignoring return value of function declared with 'nodiscard' attribute}} |
| 55 | + ec.equivalent(94, ec.default_error_condition(82)); |
| 56 | + // expected-warning@+1 {{ignoring return value of function declared with 'nodiscard' attribute}} |
| 57 | + ec.equivalent(std::error_code(49, ec), 94); |
| 58 | + // expected-warning@+1 {{ignoring return value of function declared with 'nodiscard' attribute}} |
| 59 | + ec.message(82); |
| 60 | + } |
| 61 | + { |
| 62 | + // expected-warning@+1 {{ignoring return value of function declared with 'nodiscard' attribute}} |
| 63 | + std::system_category(); |
| 64 | + |
| 65 | + const std::error_category& ec = std::system_category(); |
| 66 | + |
| 67 | + // expected-warning@+1 {{ignoring return value of function declared with 'nodiscard' attribute}} |
| 68 | + ec.name(); |
| 69 | + // expected-warning@+1 {{ignoring return value of function declared with 'nodiscard' attribute}} |
| 70 | + ec.default_error_condition(94); |
| 71 | + // expected-warning@+1 {{ignoring return value of function declared with 'nodiscard' attribute}} |
| 72 | + ec.equivalent(94, ec.default_error_condition(82)); |
| 73 | + // expected-warning@+1 {{ignoring return value of function declared with 'nodiscard' attribute}} |
| 74 | + ec.equivalent(std::error_code(49, ec), 94); |
| 75 | + // expected-warning@+1 {{ignoring return value of function declared with 'nodiscard' attribute}} |
| 76 | + ec.message(82); |
| 77 | + } |
| 78 | + { |
| 79 | + std::error_code ec; |
| 80 | + |
| 81 | + // expected-warning@+1 {{ignoring return value of function declared with 'nodiscard' attribute}} |
| 82 | + ec.value(); |
| 83 | + // expected-warning@+1 {{ignoring return value of function declared with 'nodiscard' attribute}} |
| 84 | + ec.category(); |
| 85 | + // expected-warning@+1 {{ignoring return value of function declared with 'nodiscard' attribute}} |
| 86 | + ec.default_error_condition(); |
| 87 | + |
| 88 | + // expected-warning@+1 {{ignoring return value of function declared with 'nodiscard' attribute}} |
| 89 | + ec.message(); |
| 90 | + |
| 91 | + // expected-warning@+1 {{ignoring return value of function declared with 'nodiscard' attribute}} |
| 92 | + std::make_error_code(std::errc::invalid_argument); |
| 93 | + } |
| 94 | + { |
| 95 | + std::error_condition ec; |
| 96 | + |
| 97 | + // expected-warning@+1 {{ignoring return value of function declared with 'nodiscard' attribute}} |
| 98 | + ec.value(); |
| 99 | + // expected-warning@+1 {{ignoring return value of function declared with 'nodiscard' attribute}} |
| 100 | + ec.category(); |
| 101 | + // expected-warning@+1 {{ignoring return value of function declared with 'nodiscard' attribute}} |
| 102 | + ec.message(); |
| 103 | + |
| 104 | + // expected-warning@+1 {{ignoring return value of function declared with 'nodiscard' attribute}} |
| 105 | + std::make_error_condition(std::errc::invalid_argument); |
| 106 | + } |
| 107 | + } |
| 108 | +} |
0 commit comments