@@ -3802,6 +3802,9 @@ diagnose_trait_expr (tree expr, tree args)
case CPTK_IS_SAME:
inform (loc, " %qT is not the same as %qT", t1, t2);
break;
+ case CPTK_IS_SCALAR:
+ inform (loc, " %qT is not a scalar type", t1);
+ break;
case CPTK_IS_SIGNED:
inform (loc, " %qT is not a signed type", t1);
break;
@@ -86,6 +86,7 @@ DEFTRAIT_EXPR (IS_POINTER, "__is_pointer", 1)
DEFTRAIT_EXPR (IS_POLYMORPHIC, "__is_polymorphic", 1)
DEFTRAIT_EXPR (IS_REFERENCE, "__is_reference", 1)
DEFTRAIT_EXPR (IS_SAME, "__is_same", 2)
+DEFTRAIT_EXPR (IS_SCALAR, "__is_scalar", 1)
DEFTRAIT_EXPR (IS_SIGNED, "__is_signed", 1)
DEFTRAIT_EXPR (IS_SCOPED_ENUM, "__is_scoped_enum", 1)
DEFTRAIT_EXPR (IS_STD_LAYOUT, "__is_standard_layout", 1)
@@ -12226,6 +12226,9 @@ trait_expr_value (cp_trait_kind kind, tree type1, tree type2)
case CPTK_IS_SAME:
return same_type_p (type1, type2);
+ case CPTK_IS_SCALAR:
+ return SCALAR_TYPE_P (type1);
+
case CPTK_IS_SIGNED:
return ARITHMETIC_TYPE_P (type1) && TYPE_SIGN (type1) == SIGNED;
@@ -12428,6 +12431,7 @@ finish_trait_expr (location_t loc, cp_trait_kind kind, tree type1, tree type2)
case CPTK_IS_POINTER:
case CPTK_IS_REFERENCE:
case CPTK_IS_SAME:
+ case CPTK_IS_SCALAR:
case CPTK_IS_SIGNED:
case CPTK_IS_SCOPED_ENUM:
case CPTK_IS_UNBOUNDED_ARRAY:
@@ -140,6 +140,9 @@
#if !__has_builtin (__is_same_as)
# error "__has_builtin (__is_same_as) failed"
#endif
+#if !__has_builtin (__is_scalar)
+# error "__has_builtin (__is_scalar) failed"
+#endif
#if !__has_builtin (__is_signed)
# error "__has_builtin (__is_signed) failed"
#endif
new file mode 100644
@@ -0,0 +1,31 @@
+// { dg-do compile { target c++11 } }
+
+#include <cstddef> // std::nullptr_t
+#include <testsuite_tr1.h>
+
+using namespace __gnu_test;
+
+#define SA(X) static_assert((X),#X)
+
+#define SA_TEST_CATEGORY(TRAIT, TYPE, EXPECT) \
+ SA(TRAIT(TYPE) == EXPECT); \
+ SA(TRAIT(const TYPE) == EXPECT); \
+ SA(TRAIT(volatile TYPE) == EXPECT); \
+ SA(TRAIT(const volatile TYPE) == EXPECT)
+
+// volatile return type would cause a warning.
+#define SA_FN_TEST_CATEGORY(TRAIT, TYPE, EXPECT) \
+ SA(TRAIT(TYPE) == EXPECT); \
+ SA(TRAIT(const TYPE) == EXPECT)
+
+SA_TEST_CATEGORY(__is_scalar, int, true);
+SA_TEST_CATEGORY(__is_scalar, float, true);
+SA_TEST_CATEGORY(__is_scalar, EnumType, true);
+SA_TEST_CATEGORY(__is_scalar, int*, true);
+SA_FN_TEST_CATEGORY(__is_scalar, int(*)(int), true);
+SA_TEST_CATEGORY(__is_scalar, int (ClassType::*), true);
+SA_FN_TEST_CATEGORY(__is_scalar, int (ClassType::*) (int), true);
+SA_TEST_CATEGORY(__is_scalar, std::nullptr_t, true);
+
+// Sanity check.
+SA_TEST_CATEGORY(__is_scalar, ClassType, false);