Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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/__memory/inout_ptr.h
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ class inout_ptr_t {
};

template <class _Pointer = void, class _Smart, class... _Args>
_LIBCPP_HIDE_FROM_ABI auto inout_ptr(_Smart& __s, _Args&&... __args) {
[[nodiscard]] _LIBCPP_HIDE_FROM_ABI auto inout_ptr(_Smart& __s, _Args&&... __args) {
using _Ptr = conditional_t<is_void_v<_Pointer>, __pointer_of_t<_Smart>, _Pointer>;
return std::inout_ptr_t<_Smart, _Ptr, _Args&&...>(__s, std::forward<_Args>(__args)...);
}
Expand Down
2 changes: 1 addition & 1 deletion libcxx/include/__memory/out_ptr.h
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ class out_ptr_t {
};

template <class _Pointer = void, class _Smart, class... _Args>
_LIBCPP_HIDE_FROM_ABI auto out_ptr(_Smart& __s, _Args&&... __args) {
[[nodiscard]] _LIBCPP_HIDE_FROM_ABI auto out_ptr(_Smart& __s, _Args&&... __args) {
using _Ptr = conditional_t<is_void_v<_Pointer>, __pointer_of_t<_Smart>, _Pointer>;
return std::out_ptr_t<_Smart, _Ptr, _Args&&...>(__s, std::forward<_Args>(__args)...);
}
Expand Down
14 changes: 10 additions & 4 deletions libcxx/include/fstream
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ public:
_LIBCPP_HIDE_FROM_ABI basic_filebuf* __open(int __fd, ios_base::openmode __mode);
basic_filebuf* close();
# if _LIBCPP_STD_VER >= 26
_LIBCPP_HIDE_FROM_ABI native_handle_type native_handle() const noexcept {
[[nodiscard]] _LIBCPP_HIDE_FROM_ABI native_handle_type native_handle() const noexcept {
_LIBCPP_ASSERT_UNCATEGORIZED(this->is_open(), "File must be opened");
# if defined(_LIBCPP_WIN32API)
return std::__filebuf_windows_native_handle(__file_);
Expand Down Expand Up @@ -1178,7 +1178,9 @@ public:

_LIBCPP_HIDE_FROM_ABI basic_filebuf<char_type, traits_type>* rdbuf() const;
# if _LIBCPP_STD_VER >= 26
_LIBCPP_HIDE_FROM_ABI native_handle_type native_handle() const noexcept { return rdbuf()->native_handle(); }
[[nodiscard]] _LIBCPP_HIDE_FROM_ABI native_handle_type native_handle() const noexcept {
return rdbuf()->native_handle();
}
# endif
_LIBCPP_HIDE_FROM_ABI bool is_open() const;
void open(const char* __s, ios_base::openmode __mode = ios_base::in);
Expand Down Expand Up @@ -1334,7 +1336,9 @@ public:

_LIBCPP_HIDE_FROM_ABI basic_filebuf<char_type, traits_type>* rdbuf() const;
# if _LIBCPP_STD_VER >= 26
_LIBCPP_HIDE_FROM_ABI native_handle_type native_handle() const noexcept { return rdbuf()->native_handle(); }
[[nodiscard]] _LIBCPP_HIDE_FROM_ABI native_handle_type native_handle() const noexcept {
return rdbuf()->native_handle();
}
# endif
_LIBCPP_HIDE_FROM_ABI bool is_open() const;
void open(const char* __s, ios_base::openmode __mode = ios_base::out);
Expand Down Expand Up @@ -1496,7 +1500,9 @@ public:

_LIBCPP_HIDE_FROM_ABI basic_filebuf<char_type, traits_type>* rdbuf() const;
# if _LIBCPP_STD_VER >= 26
_LIBCPP_HIDE_FROM_ABI native_handle_type native_handle() const noexcept { return rdbuf()->native_handle(); }
[[nodiscard]] _LIBCPP_HIDE_FROM_ABI native_handle_type native_handle() const noexcept {
return rdbuf()->native_handle();
}
# endif
_LIBCPP_HIDE_FROM_ABI bool is_open() const;
_LIBCPP_HIDE_FROM_ABI void open(const char* __s, ios_base::openmode __mode = ios_base::in | ios_base::out);
Expand Down
4 changes: 2 additions & 2 deletions libcxx/include/span
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,7 @@ public:
}

# if _LIBCPP_STD_VER >= 26
_LIBCPP_HIDE_FROM_ABI constexpr reference at(size_type __index) const {
[[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr reference at(size_type __index) const {
if (__index >= size())
std::__throw_out_of_range("span");
return __data_[__index];
Expand Down Expand Up @@ -527,7 +527,7 @@ public:
}

# if _LIBCPP_STD_VER >= 26
_LIBCPP_HIDE_FROM_ABI constexpr reference at(size_type __index) const {
[[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr reference at(size_type __index) const {
if (__index >= size())
std::__throw_out_of_range("span");
return __data_[__index];
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
//===----------------------------------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//

// REQUIRES: std-at-least-c++26

// <span>

// Check that functions are marked [[nodiscard]]

#include <array>
#include <span>
#include <vector>

void test() {
{ // Test with static extent
std::array arr{94, 92};
std::span sp{arr};
sp.at(0); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}}
}
{ // Test with dynamic extent
std::vector vec{94, 92};
std::span sp{vec};
sp.at(0); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
//===----------------------------------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//

// REQUIRES: std-at-least-c++26

// <fstream>

// Check that functions are marked [[nodiscard]]

#include <fstream>

void test() {
{
std::filebuf fb;
fb.native_handle(); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}}
}
{
std::fstream fs;
fs.native_handle(); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}}
}
{
std::ifstream fs;
fs.native_handle(); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}}
}
{
std::ofstream fs;
fs.native_handle(); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}}
}
}
23 changes: 23 additions & 0 deletions libcxx/test/libcxx/utilities/smartptr/adapt/nodiscard.verify.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
//===----------------------------------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//

// REQUIRES: std-at-least-c++23

// <memory>

// Check that functions are marked [[nodiscard]]

#include <memory>

void test() {
std::unique_ptr<int> uPtr;
// [inout.ptr]
std::inout_ptr(uPtr); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}}
// [out.ptr]
std::out_ptr(uPtr); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}}
}
Loading