Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[[nodiscard]] for constructors #1495

Merged
merged 5 commits into from
Dec 2, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
8 changes: 4 additions & 4 deletions stl/inc/mutex
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ _INLINE_VAR constexpr try_to_lock_t try_to_lock{};

// CLASS TEMPLATE unique_lock
template <class _Mutex>
class unique_lock { // whizzy class with destructor that unlocks mutex
class _NODISCARD_CTOR unique_lock { // whizzy class with destructor that unlocks mutex
StephanTLavavej marked this conversation as resolved.
Show resolved Hide resolved
public:
using mutex_type = _Mutex;

Expand Down Expand Up @@ -421,7 +421,7 @@ void lock(_Lock0& _Lk0, _Lock1& _Lk1, _LockN&... _LkN) { // lock multiple locks,

// CLASS TEMPLATE lock_guard
template <class _Mutex>
class lock_guard { // class with destructor that unlocks a mutex
class _NODISCARD_CTOR lock_guard { // class with destructor that unlocks a mutex
public:
using mutex_type = _Mutex;

Expand All @@ -445,7 +445,7 @@ private:
#if _HAS_CXX17
// CLASS TEMPLATE scoped_lock
template <class... _Mutexes>
class scoped_lock { // class with destructor that unlocks mutexes
class _NODISCARD_CTOR scoped_lock { // class with destructor that unlocks mutexes
public:
explicit scoped_lock(_Mutexes&... _Mtxes) : _MyMutexes(_Mtxes...) { // construct and lock
_STD lock(_Mtxes...);
Expand All @@ -465,7 +465,7 @@ private:
};

template <class _Mutex>
class scoped_lock<_Mutex> {
class _NODISCARD_CTOR scoped_lock<_Mutex> {
public:
using mutex_type = _Mutex;

Expand Down
2 changes: 1 addition & 1 deletion stl/inc/shared_mutex
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ private:

// CLASS TEMPLATE shared_lock
template <class _Mutex>
class shared_lock { // shareable lock
class _NODISCARD_CTOR shared_lock { // shareable lock
public:
using mutex_type = _Mutex;

Expand Down
4 changes: 2 additions & 2 deletions stl/inc/thread
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ private:

public:
template <class _Fn, class... _Args, enable_if_t<!is_same_v<_Remove_cvref_t<_Fn>, thread>, int> = 0>
explicit thread(_Fn&& _Fx, _Args&&... _Ax) {
_NODISCARD_CTOR explicit thread(_Fn&& _Fx, _Args&&... _Ax) {
_Start(_STD forward<_Fn>(_Fx), _STD forward<_Args>(_Ax)...);
}

Expand Down Expand Up @@ -282,7 +282,7 @@ public:
jthread() noexcept : _Impl{}, _Ssource{nostopstate} {}

template <class _Fn, class... _Args, enable_if_t<!is_same_v<remove_cvref_t<_Fn>, jthread>, int> = 0>
explicit jthread(_Fn&& _Fx, _Args&&... _Ax) {
_NODISCARD_CTOR explicit jthread(_Fn&& _Fx, _Args&&... _Ax) {
if constexpr (is_invocable_v<decay_t<_Fn>, stop_token, decay_t<_Args>...>) {
_Impl._Start(_STD forward<_Fn>(_Fx), _Ssource.get_token(), _STD forward<_Args>(_Ax)...);
} else {
Expand Down
8 changes: 8 additions & 0 deletions stl/inc/yvals_core.h
Original file line number Diff line number Diff line change
Expand Up @@ -351,6 +351,14 @@
// _HAS_NODISCARD (in vcruntime.h) controls:
// [[nodiscard]] attributes on STL functions

#ifndef __has_cpp_attribute
#define _NODISCARD_CTOR
#elif __has_cpp_attribute(nodiscard) >= 201907L
#define _NODISCARD_CTOR _NODISCARD
#else
#define _NODISCARD_CTOR
#endif

// Determine if we should use [[msvc::known_semantics]] to communicate to the compiler
// that certain type trait specializations have the standard-mandated semantics
#ifndef __has_cpp_attribute
Expand Down