Skip to content

Commit e9735f1

Browse files
committed
Rework fix for PR19460 - Use explicit bool as an extension instead.
In the previous fix I used a PMF type as a semi-safe bool type in C++03. However immediately after committing I realized clang offered explicit conversion operators as an extension. This patch removes the old fix and enables _LIBCPP_EXPLICIT using __has_extension instead. This change also affects the following other classes, which have '_LIBCPP_EXPLICIT operator bool()'. * shared_ptr * unique_ptr * error_condition * basic_ios * function (already C++11 only) * istream::sentry * experimental::string_view. In all of the above cases I believe it is safe to enable the extension, except in the experimental::string_view case. There seem to be some Clang bugs affecting the experimental::string_view conversion to std::basic_string. To work around that I manually disabled _LIBCPP_EXPLICIT in that case. llvm-svn: 290831
1 parent aa0ec1e commit e9735f1

File tree

3 files changed

+7
-19
lines changed

3 files changed

+7
-19
lines changed

libcxx/include/__config

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -727,7 +727,7 @@ template <unsigned> struct __static_assert_check {};
727727
#define _NOALIAS
728728
#endif
729729

730-
#if __has_feature(cxx_explicit_conversions) || defined(__IBMCPP__) || \
730+
#if __has_extension(cxx_explicit_conversions) || defined(__IBMCPP__) || \
731731
(!defined(_LIBCPP_CXX03_LANG) && defined(__GNUC__)) // All supported GCC versions
732732
# define _LIBCPP_EXPLICIT explicit
733733
#else

libcxx/include/experimental/string_view

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -340,7 +340,12 @@ _LIBCPP_BEGIN_NAMESPACE_LFTS
340340
// [string.view.ops], string operations:
341341
template<class _Allocator>
342342
_LIBCPP_INLINE_VISIBILITY
343-
_LIBCPP_EXPLICIT operator basic_string<_CharT, _Traits, _Allocator>() const
343+
// Clang's extended C++11 explict conversions don't work with
344+
// string_view in C++03.
345+
#ifndef _LIBCPP_CXX03_LANG
346+
_LIBCPP_EXPLICIT
347+
#endif
348+
operator basic_string<_CharT, _Traits, _Allocator>() const
344349
{ return basic_string<_CharT, _Traits, _Allocator>( begin(), end()); }
345350

346351
template<class _Allocator = allocator<_CharT> >

libcxx/include/ios

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -572,13 +572,6 @@ ios_base::exceptions(iostate __iostate)
572572
clear(__rdstate_);
573573
}
574574

575-
#if defined(_LIBCPP_CXX03_LANG)
576-
struct _LIBCPP_TYPE_VIS_ONLY __cxx03_bool {
577-
typedef void (__cxx03_bool::*__bool_type)();
578-
void __true_value() {}
579-
};
580-
#endif
581-
582575
template <class _CharT, class _Traits>
583576
class _LIBCPP_TYPE_VIS_ONLY basic_ios
584577
: public ios_base
@@ -592,18 +585,8 @@ public:
592585
typedef typename traits_type::pos_type pos_type;
593586
typedef typename traits_type::off_type off_type;
594587

595-
// __true_value will generate undefined references when linking unless
596-
// we give it internal linkage.
597-
598-
#if defined(_LIBCPP_CXX03_LANG)
599-
_LIBCPP_ALWAYS_INLINE
600-
operator __cxx03_bool::__bool_type() const {
601-
return !fail() ? &__cxx03_bool::__true_value : nullptr;
602-
}
603-
#else
604588
_LIBCPP_ALWAYS_INLINE
605589
_LIBCPP_EXPLICIT operator bool() const {return !fail();}
606-
#endif
607590

608591
_LIBCPP_ALWAYS_INLINE bool operator!() const {return fail();}
609592
_LIBCPP_ALWAYS_INLINE iostate rdstate() const {return ios_base::rdstate();}

0 commit comments

Comments
 (0)