@@ -3747,6 +3747,9 @@ diagnose_trait_expr (tree expr, tree args)
case CPTK_IS_UNION:
inform (loc, " %qT is not a union", t1);
break;
+ case CPTK_IS_SCALAR:
+ inform(loc, " %qT is not a scalar type", t1);
+ break;
case CPTK_IS_AGGREGATE:
inform (loc, " %qT is not an aggregate", t1);
break;
@@ -82,6 +82,7 @@ DEFTRAIT_EXPR (IS_TRIVIALLY_ASSIGNABLE, "__is_trivially_assignable", 2)
DEFTRAIT_EXPR (IS_TRIVIALLY_CONSTRUCTIBLE, "__is_trivially_constructible", -1)
DEFTRAIT_EXPR (IS_TRIVIALLY_COPYABLE, "__is_trivially_copyable", 1)
DEFTRAIT_EXPR (IS_UNION, "__is_union", 1)
+DEFTRAIT_EXPR (IS_SCALAR, "__is_scalar", 1)
DEFTRAIT_EXPR (REF_CONSTRUCTS_FROM_TEMPORARY, "__reference_constructs_from_temporary", 2)
DEFTRAIT_EXPR (REF_CONVERTS_FROM_TEMPORARY, "__reference_converts_from_temporary", 2)
@@ -437,7 +437,8 @@ pp_cxx_userdef_literal (cxx_pretty_printer *pp, tree t)
__is_polymorphic ( type-id )
__is_std_layout ( type-id )
__is_trivial ( type-id )
- __is_union ( type-id ) */
+ __is_union ( type-id )
+ __is_scalar ( type-id ) */
void
cxx_pretty_printer::primary_expression (tree t)
@@ -5577,6 +5577,7 @@ cp_parser_fold_expression (cp_parser *parser, tree expr1)
__is_std_layout ( type-id )
__is_trivial ( type-id )
__is_union ( type-id )
+ __is_scalar ( type-id )
Objective-C++ Extension:
@@ -12025,6 +12025,9 @@ trait_expr_value (cp_trait_kind kind, tree type1, tree type2)
case CPTK_IS_UNION:
return type_code1 == UNION_TYPE;
+ case CPTK_IS_SCALAR:
+ return SCALAR_TYPE_P (type1);
+
case CPTK_IS_ASSIGNABLE:
return is_xible (MODIFY_EXPR, type1, type2);
@@ -12190,6 +12193,7 @@ finish_trait_expr (location_t loc, cp_trait_kind kind, tree type1, tree type2)
case CPTK_IS_CLASS:
case CPTK_IS_ENUM:
case CPTK_IS_UNION:
+ case CPTK_IS_SCALAR:
case CPTK_IS_SAME:
break;
@@ -146,3 +146,7 @@
#if !__has_builtin (__remove_cvref)
# error "__has_builtin (__remove_cvref) failed"
#endif
+#if !__has_builtin (__is_scalar)
+# error "__has_builtin (__is_scalar) failed"
+#endif
+
new file mode 100644
@@ -0,0 +1,21 @@
+// { dg-do compile { target c++11 } }
+
+#define SA(X) static_assert((X),#X)
+
+struct S { int m; };
+
+enum class E {
+ e
+};
+
+int main() {
+ char* pNull= nullptr;
+
+ SA(__is_scalar(decltype(pNull)));
+ SA(__is_scalar(int));
+ SA(__is_scalar(double));
+ SA(__is_scalar(E));
+ SA(__is_scalar(char const *));
+ SA(!__is_scalar(struct S));
+ return 0;
+}
\ No newline at end of file
@@ -225,7 +225,7 @@ namespace std __attribute__ ((__visibility__ ("default"))) {
: public __traitor<__is_void<_Tp>, __is_arithmetic<_Tp> >
{ };
template<typename _Tp>
- struct __is_scalar
+ struct __is_arith_or_ptr
: public __traitor<__is_arithmetic<_Tp>, __is_pointer<_Tp> >
{ };
template<typename _Tp>
@@ -1325,7 +1325,7 @@ namespace std __attribute__ ((__visibility__ ("default"))) {
}
template<typename _ForwardIterator, typename _Tp>
inline typename
- __gnu_cxx::__enable_if<!__is_scalar<_Tp>::__value, void>::__type
+ __gnu_cxx::__enable_if<!__is_arith_or_ptr<_Tp>::__value, void>::__type
__fill_a(_ForwardIterator __first, _ForwardIterator __last,
const _Tp& __value)
{
@@ -1334,7 +1334,7 @@ namespace std __attribute__ ((__visibility__ ("default"))) {
}
template<typename _ForwardIterator, typename _Tp>
inline typename
- __gnu_cxx::__enable_if<__is_scalar<_Tp>::__value, void>::__type
+ __gnu_cxx::__enable_if<__is_arith_or_ptr<_Tp>::__value, void>::__type
__fill_a(_ForwardIterator __first, _ForwardIterator __last,
const _Tp& __value)
{
@@ -1362,7 +1362,7 @@ namespace std __attribute__ ((__visibility__ ("default"))) {
}
template<typename _OutputIterator, typename _Size, typename _Tp>
inline typename
- __gnu_cxx::__enable_if<!__is_scalar<_Tp>::__value, _OutputIterator>::__type
+ __gnu_cxx::__enable_if<!__is_arith_or_ptr<_Tp>::__value, _OutputIterator>::__type
__fill_n_a(_OutputIterator __first, _Size __n, const _Tp& __value)
{
for (; __n > 0; --__n, ++__first)
@@ -1371,7 +1371,7 @@ namespace std __attribute__ ((__visibility__ ("default"))) {
}
template<typename _OutputIterator, typename _Size, typename _Tp>
inline typename
- __gnu_cxx::__enable_if<__is_scalar<_Tp>::__value, _OutputIterator>::__type
+ __gnu_cxx::__enable_if<__is_arith_or_ptr<_Tp>::__value, _OutputIterator>::__type
__fill_n_a(_OutputIterator __first, _Size __n, const _Tp& __value)
{
const _Tp __tmp = __value;
@@ -27,7 +27,7 @@ namespace std __attribute__ ((__visibility__ ("default"))) {
};
template<typename _Tp> struct __is_arithmetic : public __traitor<__is_integer<_Tp>, __is_floating<_Tp> > {
};
- template<typename _Tp> struct __is_scalar : public __traitor<__is_arithmetic<_Tp>, __is_pointer<_Tp> > {
+ template<typename _Tp> struct __is_arith_or_ptr : public __traitor<__is_arithmetic<_Tp>, __is_pointer<_Tp> > {
};
}
namespace __gnu_cxx __attribute__ ((__visibility__ ("default"))) {
@@ -54,7 +54,7 @@ namespace std __attribute__ ((__visibility__ ("default"))) {
};
template<typename _Iterator> inline typename _Niter_base<_Iterator>::iterator_type __niter_base(_Iterator __it) {
}
- template<typename _OutputIterator, typename _Size, typename _Tp> inline typename __gnu_cxx::__enable_if<!__is_scalar<_Tp>::__value, _OutputIterator>::__type __fill_n_a(_OutputIterator __first, _Size __n, const _Tp& __value) {
+ template<typename _OutputIterator, typename _Size, typename _Tp> inline typename __gnu_cxx::__enable_if<!__is_arith_or_ptr<_Tp>::__value, _OutputIterator>::__type __fill_n_a(_OutputIterator __first, _Size __n, const _Tp& __value) {
for (__decltype(__n + 0) __niter = __n;
__niter > 0;
--__niter, ++__first) *__first = __value;
@@ -387,9 +387,9 @@ __INT_N(__GLIBCXX_TYPE_INT_N_3)
//
// A scalar type is an arithmetic type or a pointer type
- //
+ //
template<typename _Tp>
- struct __is_scalar
+ struct __is_arith_or_ptr
: public __traitor<__is_arithmetic<_Tp>, __is_pointer<_Tp> >
{ };
@@ -911,7 +911,7 @@ _GLIBCXX_END_NAMESPACE_CONTAINER
template<typename _ForwardIterator, typename _Tp>
_GLIBCXX20_CONSTEXPR
inline typename
- __gnu_cxx::__enable_if<!__is_scalar<_Tp>::__value, void>::__type
+ __gnu_cxx::__enable_if<!__is_arith_or_ptr<_Tp>::__value, void>::__type
__fill_a1(_ForwardIterator __first, _ForwardIterator __last,
const _Tp& __value)
{
@@ -922,7 +922,7 @@ _GLIBCXX_END_NAMESPACE_CONTAINER
template<typename _ForwardIterator, typename _Tp>
_GLIBCXX20_CONSTEXPR
inline typename
- __gnu_cxx::__enable_if<__is_scalar<_Tp>::__value, void>::__type
+ __gnu_cxx::__enable_if<__is_arith_or_ptr<_Tp>::__value, void>::__type
__fill_a1(_ForwardIterator __first, _ForwardIterator __last,
const _Tp& __value)
{
@@ -1060,7 +1060,7 @@ _GLIBCXX_END_NAMESPACE_CONTAINER
template<typename _OutputIterator, typename _Size, typename _Tp>
_GLIBCXX20_CONSTEXPR
inline typename
- __gnu_cxx::__enable_if<!__is_scalar<_Tp>::__value, _OutputIterator>::__type
+ __gnu_cxx::__enable_if<!__is_arith_or_ptr<_Tp>::__value, _OutputIterator>::__type
__fill_n_a1(_OutputIterator __first, _Size __n, const _Tp& __value)
{
for (; __n > 0; --__n, (void) ++__first)
@@ -1071,7 +1071,7 @@ _GLIBCXX_END_NAMESPACE_CONTAINER
template<typename _OutputIterator, typename _Size, typename _Tp>
_GLIBCXX20_CONSTEXPR
inline typename
- __gnu_cxx::__enable_if<__is_scalar<_Tp>::__value, _OutputIterator>::__type
+ __gnu_cxx::__enable_if<__is_arith_or_ptr<_Tp>::__value, _OutputIterator>::__type
__fill_n_a1(_OutputIterator __first, _Size __n, const _Tp& __value)
{
const _Tp __tmp = __value;
@@ -90,7 +90,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
inline void
__valarray_default_construct(_Tp* __b, _Tp* __e)
{
- _Array_default_ctor<_Tp, __is_scalar<_Tp>::__value>::_S_do_it(__b, __e);
+ _Array_default_ctor<_Tp, __is_arith_or_ptr<_Tp>::__value>::_S_do_it(__b, __e);
}
// Turn a raw-memory into an array of _Tp filled with __t
@@ -678,11 +678,18 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
struct is_member_pointer;
/// is_scalar
+#if __has_builtin(__is_scalar)
+ template<typename _Tp>
+ struct is_scalar
+ : public __bool_constant<__is_scalar(_Tp)>
+ { };
+#else
template<typename _Tp>
struct is_scalar
: public __or_<is_arithmetic<_Tp>, is_enum<_Tp>, is_pointer<_Tp>,
is_member_pointer<_Tp>, is_null_pointer<_Tp>>::type
{ };
+#endif
/// is_compound
template<typename _Tp>