Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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/__format/format_args.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class basic_format_args {
}
}

_LIBCPP_HIDE_FROM_ABI basic_format_arg<_Context> get(size_t __id) const noexcept {
[[nodiscard]] _LIBCPP_HIDE_FROM_ABI basic_format_arg<_Context> get(size_t __id) const noexcept {
if (__id >= __size_)
return basic_format_arg<_Context>{};

Expand Down
6 changes: 3 additions & 3 deletions libcxx/include/__format/format_context.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,17 +80,17 @@ class _LIBCPP_PREFERRED_NAME(format_context)
template <class _Tp>
using formatter_type = formatter<_Tp, _CharT>;

_LIBCPP_HIDE_FROM_ABI basic_format_arg<basic_format_context> arg(size_t __id) const noexcept {
[[nodiscard]] _LIBCPP_HIDE_FROM_ABI basic_format_arg<basic_format_context> arg(size_t __id) const noexcept {
return __args_.get(__id);
}
# if _LIBCPP_HAS_LOCALIZATION
_LIBCPP_HIDE_FROM_ABI std::locale locale() {
[[nodiscard]] _LIBCPP_HIDE_FROM_ABI std::locale locale() {
if (!__loc_)
__loc_ = std::locale{};
return *__loc_;
}
# endif
_LIBCPP_HIDE_FROM_ABI iterator out() { return std::move(__out_it_); }
[[nodiscard]] _LIBCPP_HIDE_FROM_ABI iterator out() { return std::move(__out_it_); }
_LIBCPP_HIDE_FROM_ABI void advance_to(iterator __it) { __out_it_ = std::move(__it); }

private:
Expand Down
4 changes: 2 additions & 2 deletions libcxx/include/__format/format_parse_context.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ class basic_format_parse_context {
basic_format_parse_context(const basic_format_parse_context&) = delete;
basic_format_parse_context& operator=(const basic_format_parse_context&) = delete;

_LIBCPP_HIDE_FROM_ABI constexpr const_iterator begin() const noexcept { return __begin_; }
_LIBCPP_HIDE_FROM_ABI constexpr const_iterator end() const noexcept { return __end_; }
[[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr const_iterator begin() const noexcept { return __begin_; }
[[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr const_iterator end() const noexcept { return __end_; }
_LIBCPP_HIDE_FROM_ABI constexpr void advance_to(const_iterator __it) { __begin_ = __it; }

_LIBCPP_HIDE_FROM_ABI constexpr size_t next_arg_id() {
Expand Down
23 changes: 23 additions & 0 deletions libcxx/test/libcxx/diagnostics/format.nodiscard.verify.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@
// UNSUPPORTED: c++03, c++11, c++14, c++17

#include <format>
#include <string>

#include "test_format_context.h"
#include "test_macros.h"

#ifndef TEST_HAS_NO_LOCALIZATION
Expand Down Expand Up @@ -46,4 +48,25 @@ void test() {
# endif // TEST_HAS_NO_WIDE_CHARACTERS
#endif // TEST_HAS_NO_LOCALIZATION
// clang-format on

std::basic_format_args args{std::make_format_args()};

args.get(0); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}}

using OutItT = std::back_insert_iterator<std::string>;
std::string str;
OutItT outIt{str};
using FormatCtxT = std::basic_format_context<OutItT, char>;
FormatCtxT fCtx = test_format_context_create<OutItT, char>(outIt, std::make_format_args<FormatCtxT>());

fCtx.arg(0); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}}
#if !defined(TEST_HAS_NO_LOCALIZATION)
fCtx.locale(); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}}
#endif
fCtx.out(); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}}

std::basic_format_parse_context<char> fpCtx{""};

fpCtx.begin(); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}}
fpCtx.end(); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}}
}
Loading