# define _LIBCPP_NOALIAS
#endif
-#if __has_feature(cxx_explicit_conversions) || defined(__IBMCPP__) || \
- (!defined(_LIBCPP_CXX03_LANG) && defined(__GNUC__)) // All supported GCC versions
-# define _LIBCPP_EXPLICIT explicit
-#else
-# define _LIBCPP_EXPLICIT
-#endif
-
#if __has_attribute(using_if_exists)
# define _LIBCPP_USING_IF_EXISTS __attribute__((using_if_exists))
#else
{function(allocator_arg, __a, __f).swap(*this);}
// 20.7.16.2.3, function capacity:
- _LIBCPP_INLINE_VISIBILITY operator bool() const {return __f_;}
+ _LIBCPP_INLINE_VISIBILITY explicit operator bool() const {return __f_;}
private:
// deleted overloads close possible hole in the type system
{function(allocator_arg, __a, __f).swap(*this);}
// 20.7.16.2.3, function capacity:
- _LIBCPP_INLINE_VISIBILITY operator bool() const {return __f_;}
+ _LIBCPP_INLINE_VISIBILITY explicit operator bool() const {return __f_;}
private:
// deleted overloads close possible hole in the type system
{function(allocator_arg, __a, __f).swap(*this);}
// 20.7.16.2.3, function capacity:
- operator bool() const {return __f_;}
+ _LIBCPP_INLINE_VISIBILITY explicit operator bool() const {return __f_;}
private:
// deleted overloads close possible hole in the type system
{function(allocator_arg, __a, __f).swap(*this);}
// 20.7.16.2.3, function capacity:
- _LIBCPP_INLINE_VISIBILITY operator bool() const {return __f_;}
+ _LIBCPP_INLINE_VISIBILITY explicit operator bool() const {return __f_;}
private:
// deleted overloads close possible hole in the type system
_LIBCPP_INLINE_VISIBILITY
bool unique() const _NOEXCEPT {return use_count() == 1;}
_LIBCPP_INLINE_VISIBILITY
- _LIBCPP_EXPLICIT operator bool() const _NOEXCEPT {return get() != nullptr;}
+ explicit operator bool() const _NOEXCEPT {return get() != nullptr;}
template <class _Up>
_LIBCPP_INLINE_VISIBILITY
bool owner_before(shared_ptr<_Up> const& __p) const _NOEXCEPT
return __ptr_.second();
}
_LIBCPP_INLINE_VISIBILITY
- _LIBCPP_EXPLICIT operator bool() const _NOEXCEPT {
+ explicit operator bool() const _NOEXCEPT {
return __ptr_.first() != nullptr;
}
return __ptr_.second();
}
_LIBCPP_INLINE_VISIBILITY
- _LIBCPP_EXPLICIT operator bool() const _NOEXCEPT {
+ explicit operator bool() const _NOEXCEPT {
return __ptr_.first() != nullptr;
}
_LIBCPP_INLINE_VISIBILITY
bool owns_lock() const _NOEXCEPT {return __owns_;}
_LIBCPP_INLINE_VISIBILITY
- _LIBCPP_EXPLICIT
- operator bool () const _NOEXCEPT {return __owns_;}
+ explicit operator bool() const _NOEXCEPT {return __owns_;}
_LIBCPP_INLINE_VISIBILITY
mutex_type* mutex() const _NOEXCEPT {return __m_;}
};
exception_ptr& operator=(const exception_ptr&) _NOEXCEPT;
~exception_ptr() _NOEXCEPT;
- _LIBCPP_INLINE_VISIBILITY _LIBCPP_EXPLICIT operator bool() const _NOEXCEPT
+ _LIBCPP_INLINE_VISIBILITY explicit operator bool() const _NOEXCEPT
{return __ptr_ != nullptr;}
friend _LIBCPP_INLINE_VISIBILITY
exception_ptr& operator=(const exception_ptr& __other) _NOEXCEPT;
exception_ptr& operator=(nullptr_t) _NOEXCEPT;
~exception_ptr() _NOEXCEPT;
- _LIBCPP_EXPLICIT operator bool() const _NOEXCEPT;
+ explicit operator bool() const _NOEXCEPT;
};
_LIBCPP_FUNC_VIS
}
_LIBCPP_INLINE_VISIBILITY
- _LIBCPP_EXPLICIT operator bool() const _NOEXCEPT { return __f_ != nullptr; }
+ explicit operator bool() const _NOEXCEPT { return __f_ != nullptr; }
#ifndef _LIBCPP_NO_RTTI
_LIBCPP_INLINE_VISIBILITY
// function capacity:
_LIBCPP_INLINE_VISIBILITY
- _LIBCPP_EXPLICIT operator bool() const _NOEXCEPT {
+ explicit operator bool() const _NOEXCEPT {
return static_cast<bool>(__f_);
}
clear(__rdstate_);
}
-#if defined(_LIBCPP_CXX03_LANG)
-struct _LIBCPP_TYPE_VIS __cxx03_bool {
- typedef void (__cxx03_bool::*__bool_type)();
- void __true_value() {}
-};
-#endif
-
template <class _CharT, class _Traits>
class _LIBCPP_TEMPLATE_VIS basic_ios
: public ios_base
static_assert((is_same<_CharT, typename traits_type::char_type>::value),
"traits_type::char_type must be the same type as CharT");
- // __true_value will generate undefined references when linking unless
- // we give it internal linkage.
-
-#if defined(_LIBCPP_CXX03_LANG)
_LIBCPP_INLINE_VISIBILITY
- operator __cxx03_bool::__bool_type() const {
- return !fail() ? &__cxx03_bool::__true_value : nullptr;
- }
-#else
- _LIBCPP_INLINE_VISIBILITY
- _LIBCPP_EXPLICIT operator bool() const {return !fail();}
-#endif
+ explicit operator bool() const {return !fail();}
_LIBCPP_INLINE_VISIBILITY bool operator!() const {return fail();}
_LIBCPP_INLINE_VISIBILITY iostate rdstate() const {return ios_base::rdstate();}
// ~sentry() = default;
_LIBCPP_INLINE_VISIBILITY
- _LIBCPP_EXPLICIT
- operator bool() const {return __ok_;}
+ explicit operator bool() const {return __ok_;}
};
template <class _CharT, class _Traits>
~sentry();
_LIBCPP_INLINE_VISIBILITY
- _LIBCPP_EXPLICIT
- operator bool() const {return __ok_;}
+ explicit operator bool() const {return __ok_;}
};
template <class _CharT, class _Traits>
string message() const;
_LIBCPP_INLINE_VISIBILITY
- _LIBCPP_EXPLICIT
- operator bool() const _NOEXCEPT {return __val_ != 0;}
+ explicit operator bool() const _NOEXCEPT {return __val_ != 0;}
};
inline _LIBCPP_INLINE_VISIBILITY
string message() const;
_LIBCPP_INLINE_VISIBILITY
- _LIBCPP_EXPLICIT
- operator bool() const _NOEXCEPT {return __val_ != 0;}
+ explicit operator bool() const _NOEXCEPT {return __val_ != 0;}
};
inline _LIBCPP_INLINE_VISIBILITY
+++ /dev/null
-//===----------------------------------------------------------------------===//
-//
-// 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
-//
-//===----------------------------------------------------------------------===//
-
-// XFAIL: c++03
-
-// <system_error>
-
-// class error_code
-
-// explicit operator bool() const;
-
-#include <system_error>
-
-bool test_func(void)
-{
- const std::error_code ec(0, std::generic_category());
- return ec; // conversion to bool is explicit; should fail.
-}
-
-int main(int, char**)
-{
- return 0;
-}
// explicit operator bool() const;
#include <system_error>
-#include <string>
#include <cassert>
+#include <string>
+#include <type_traits>
#include "test_macros.h"
int main(int, char**)
{
+ static_assert(std::is_constructible<bool, std::error_code>::value, "");
+ static_assert(!std::is_convertible<std::error_code, bool>::value, "");
+
{
const std::error_code ec(6, std::generic_category());
assert(static_cast<bool>(ec));
static_assert((!std::is_convertible<std::ios, void*>::value), "");
static_assert((!std::is_convertible<std::ios, int>::value), "");
static_assert((!std::is_convertible<std::ios const&, int>::value), "");
-#if TEST_STD_VER >= 11
static_assert((!std::is_convertible<std::ios, bool>::value), "");
-#endif
return 0;
}
#include <exception>
#include <cassert>
+#include <type_traits>
#include "test_macros.h"
p3 = nullptr;
assert(p3 == nullptr);
- return 0;
+ return 0;
}
// UNSUPPORTED: libcpp-has-no-threads
// UNSUPPORTED: c++03, c++11
-// dylib support for shared_mutex was added in macosx10.12
-// XFAIL: use_system_cxx_lib && x86_64-apple-macosx10.11
-// XFAIL: use_system_cxx_lib && x86_64-apple-macosx10.10
-// XFAIL: use_system_cxx_lib && x86_64-apple-macosx10.9
-
// <shared_mutex>
// template <class Mutex> class shared_lock;
#include "test_macros.h"
-std::shared_timed_mutex m;
+struct M {
+ void lock_shared() {}
+ void unlock_shared() {}
+};
int main(int, char**)
{
- std::shared_lock<std::shared_timed_mutex> lk0;
+ static_assert(std::is_constructible<bool, std::shared_lock<M>>::value, "");
+ static_assert(!std::is_convertible<std::shared_lock<M>, bool>::value, "");
+
+ M m;
+ std::shared_lock<M> lk0;
assert(static_cast<bool>(lk0) == false);
- std::shared_lock<std::shared_timed_mutex> lk1(m);
+ std::shared_lock<M> lk1(m);
assert(static_cast<bool>(lk1) == true);
lk1.unlock();
assert(static_cast<bool>(lk1) == false);
- static_assert(noexcept(static_cast<bool>(lk0)), "explicit operator bool() must be noexcept");
+ ASSERT_NOEXCEPT(static_cast<bool>(lk0));
- return 0;
+ return 0;
}
// template <class Mutex> class unique_lock;
-// explicit operator bool() const;
+// explicit operator bool() const noexcept;
#include <mutex>
#include <cassert>
+#include <type_traits>
#include "test_macros.h"
int main(int, char**)
{
+ static_assert(std::is_constructible<bool, std::unique_lock<std::mutex> >::value, "");
+ static_assert(!std::is_convertible<std::unique_lock<std::mutex>, bool>::value, "");
+
std::unique_lock<std::mutex> lk0;
assert(static_cast<bool>(lk0) == false);
std::unique_lock<std::mutex> lk1(m);
assert(static_cast<bool>(lk1) == true);
lk1.unlock();
assert(static_cast<bool>(lk1) == false);
+ ASSERT_NOEXCEPT(static_cast<bool>(lk0));
return 0;
}
#include <functional>
#include <cassert>
+#include <type_traits>
#include "test_macros.h"
int main(int, char**)
{
+ static_assert(std::is_constructible<bool, std::function<void()> >::value, "");
+ static_assert(!std::is_convertible<std::function<void()>, bool>::value, "");
+
{
std::function<int(int)> f;
assert(!f);
#include <memory>
#include <cassert>
+#include <type_traits>
#include "test_macros.h"
int main(int, char**)
{
+ static_assert(std::is_constructible<bool, std::shared_ptr<A> >::value, "");
+ static_assert(!std::is_convertible<std::shared_ptr<A>, bool>::value, "");
+
{
const std::shared_ptr<int> p(new int(32));
assert(p);