]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
c++: Sort built-in traits alphabetically
authorKen Matsui <kmatsui@gcc.gnu.org>
Thu, 7 Dec 2023 05:32:56 +0000 (21:32 -0800)
committerJason Merrill <jason@redhat.com>
Sun, 10 Dec 2023 18:11:22 +0000 (13:11 -0500)
This patch sorts built-in traits alphabetically for better code
readability.

gcc/cp/ChangeLog:

* constraint.cc (diagnose_trait_expr): Sort built-in traits
alphabetically.
* cp-trait.def: Likewise.
* semantics.cc (trait_expr_value): Likewise.
(finish_trait_expr): Likewise.
(finish_trait_type): Likewise.

gcc/testsuite/ChangeLog:

* g++.dg/ext/has-builtin-1.C: Sort built-in traits alphabetically.

Signed-off-by: Ken Matsui <kmatsui@gcc.gnu.org>
gcc/cp/constraint.cc
gcc/cp/cp-trait.def
gcc/cp/semantics.cc
gcc/testsuite/g++.dg/ext/has-builtin-1.C

index d9972d697251a9afe338eba71d81319df7f6e902..29aa7bb3df842eb51e8c10f42f05d5f9971dd00e 100644 (file)
@@ -3707,18 +3707,36 @@ diagnose_trait_expr (tree expr, tree args)
     case CPTK_HAS_TRIVIAL_DESTRUCTOR:
       inform (loc, "  %qT is not trivially destructible", t1);
       break;
+    case CPTK_HAS_UNIQUE_OBJ_REPRESENTATIONS:
+      inform (loc, "  %qT does not have unique object representations", t1);
+      break;
     case CPTK_HAS_VIRTUAL_DESTRUCTOR:
       inform (loc, "  %qT does not have a virtual destructor", t1);
       break;
     case CPTK_IS_ABSTRACT:
       inform (loc, "  %qT is not an abstract class", t1);
       break;
+    case CPTK_IS_AGGREGATE:
+      inform (loc, "  %qT is not an aggregate", t1);
+      break;
+    case CPTK_IS_ASSIGNABLE:
+      inform (loc, "  %qT is not assignable from %qT", t1, t2);
+      break;
     case CPTK_IS_BASE_OF:
       inform (loc, "  %qT is not a base of %qT", t1, t2);
       break;
     case CPTK_IS_CLASS:
       inform (loc, "  %qT is not a class", t1);
       break;
+    case CPTK_IS_CONSTRUCTIBLE:
+      if (!t2)
+    inform (loc, "  %qT is not default constructible", t1);
+      else
+    inform (loc, "  %qT is not constructible from %qE", t1, t2);
+      break;
+    case CPTK_IS_CONVERTIBLE:
+      inform (loc, "  %qT is not convertible from %qE", t2, t1);
+      break;
     case CPTK_IS_EMPTY:
       inform (loc, "  %qT is not an empty class", t1);
       break;
@@ -3734,6 +3752,18 @@ diagnose_trait_expr (tree expr, tree args)
     case CPTK_IS_LITERAL_TYPE:
       inform (loc, "  %qT is not a literal type", t1);
       break;
+    case CPTK_IS_NOTHROW_ASSIGNABLE:
+      inform (loc, "  %qT is not nothrow assignable from %qT", t1, t2);
+      break;
+    case CPTK_IS_NOTHROW_CONSTRUCTIBLE:
+      if (!t2)
+       inform (loc, "  %qT is not nothrow default constructible", t1);
+      else
+       inform (loc, "  %qT is not nothrow constructible from %qE", t1, t2);
+      break;
+    case CPTK_IS_NOTHROW_CONVERTIBLE:
+         inform (loc, "  %qT is not nothrow convertible from %qE", t2, t1);
+      break;
     case CPTK_IS_POINTER_INTERCONVERTIBLE_BASE_OF:
       inform (loc, "  %qT is not pointer-interconvertible base of %qT",
              t1, t2);
@@ -3753,50 +3783,20 @@ diagnose_trait_expr (tree expr, tree args)
     case CPTK_IS_TRIVIAL:
       inform (loc, "  %qT is not a trivial type", t1);
       break;
-    case CPTK_IS_UNION:
-      inform (loc, "  %qT is not a union", t1);
-      break;
-    case CPTK_IS_AGGREGATE:
-      inform (loc, "  %qT is not an aggregate", t1);
-      break;
-    case CPTK_IS_TRIVIALLY_COPYABLE:
-      inform (loc, "  %qT is not trivially copyable", t1);
-      break;
-    case CPTK_IS_ASSIGNABLE:
-      inform (loc, "  %qT is not assignable from %qT", t1, t2);
-      break;
     case CPTK_IS_TRIVIALLY_ASSIGNABLE:
       inform (loc, "  %qT is not trivially assignable from %qT", t1, t2);
       break;
-    case CPTK_IS_NOTHROW_ASSIGNABLE:
-      inform (loc, "  %qT is not nothrow assignable from %qT", t1, t2);
-      break;
-    case CPTK_IS_CONSTRUCTIBLE:
-      if (!t2)
-       inform (loc, "  %qT is not default constructible", t1);
-      else
-       inform (loc, "  %qT is not constructible from %qE", t1, t2);
-      break;
     case CPTK_IS_TRIVIALLY_CONSTRUCTIBLE:
       if (!t2)
        inform (loc, "  %qT is not trivially default constructible", t1);
       else
        inform (loc, "  %qT is not trivially constructible from %qE", t1, t2);
       break;
-    case CPTK_IS_NOTHROW_CONSTRUCTIBLE:
-      if (!t2)
-       inform (loc, "  %qT is not nothrow default constructible", t1);
-      else
-       inform (loc, "  %qT is not nothrow constructible from %qE", t1, t2);
-      break;
-    case CPTK_HAS_UNIQUE_OBJ_REPRESENTATIONS:
-      inform (loc, "  %qT does not have unique object representations", t1);
-      break;
-    case CPTK_IS_CONVERTIBLE:
-      inform (loc, "  %qT is not convertible from %qE", t2, t1);
+    case CPTK_IS_TRIVIALLY_COPYABLE:
+      inform (loc, "  %qT is not trivially copyable", t1);
       break;
-    case CPTK_IS_NOTHROW_CONVERTIBLE:
-       inform (loc, "  %qT is not nothrow convertible from %qE", t2, t1);
+    case CPTK_IS_UNION:
+      inform (loc, "  %qT is not a union", t1);
       break;
     case CPTK_REF_CONSTRUCTS_FROM_TEMPORARY:
       inform (loc, "  %qT is not a reference that binds to a temporary "
index 8b7fece0cc86e5a666c8b1104837a452ccaa02e3..0e48e64b8dd70928c946fc928c84afb4823f8a49 100644 (file)
@@ -84,14 +84,14 @@ DEFTRAIT_EXPR (IS_TRIVIALLY_COPYABLE, "__is_trivially_copyable", 1)
 DEFTRAIT_EXPR (IS_UNION, "__is_union", 1)
 DEFTRAIT_EXPR (REF_CONSTRUCTS_FROM_TEMPORARY, "__reference_constructs_from_temporary", 2)
 DEFTRAIT_EXPR (REF_CONVERTS_FROM_TEMPORARY, "__reference_converts_from_temporary", 2)
-/* FIXME Added space to avoid direct usage in GCC 13.  */
-DEFTRAIT_EXPR (IS_DEDUCIBLE, "__is_deducible ", 2)
-
 DEFTRAIT_TYPE (REMOVE_CV, "__remove_cv", 1)
-DEFTRAIT_TYPE (REMOVE_REFERENCE, "__remove_reference", 1)
 DEFTRAIT_TYPE (REMOVE_CVREF, "__remove_cvref", 1)
-DEFTRAIT_TYPE (UNDERLYING_TYPE,  "__underlying_type", 1)
+DEFTRAIT_TYPE (REMOVE_REFERENCE, "__remove_reference", 1)
 DEFTRAIT_TYPE (TYPE_PACK_ELEMENT, "__type_pack_element", -1)
+DEFTRAIT_TYPE (UNDERLYING_TYPE, "__underlying_type", 1)
+
+/* FIXME Added space to avoid direct usage in GCC 13.  */
+DEFTRAIT_EXPR (IS_DEDUCIBLE, "__is_deducible ", 2)
 
 /* These traits yield a type pack, not a type, and are represented by
    cp_parser_trait as a special BASES tree instead of a TRAIT_TYPE tree.  */
index efd959d95b9f885d7feaeddfddd2f1fc98df9179..23d1f12e371441f8b2b42e31fd9025f7e16b8b35 100644 (file)
@@ -12334,15 +12334,6 @@ trait_expr_value (cp_trait_kind kind, tree type1, tree type2)
                      && classtype_has_nothrow_assign_or_copy_p (type1,
                                                                 true))));
 
-    case CPTK_HAS_TRIVIAL_ASSIGN:
-      /* ??? The standard seems to be missing the "or array of such a class
-        type" wording for this trait.  */
-      type1 = strip_array_types (type1);
-      return (!CP_TYPE_CONST_P (type1) && type_code1 != REFERENCE_TYPE
-             && (trivial_type_p (type1)
-                   || (CLASS_TYPE_P (type1)
-                       && TYPE_HAS_TRIVIAL_COPY_ASSIGN (type1))));
-
     case CPTK_HAS_NOTHROW_CONSTRUCTOR:
       type1 = strip_array_types (type1);
       return (trait_expr_value (CPTK_HAS_TRIVIAL_CONSTRUCTOR, type1, type2)
@@ -12351,17 +12342,26 @@ trait_expr_value (cp_trait_kind kind, tree type1, tree type2)
                  && maybe_instantiate_noexcept (t)
                  && TYPE_NOTHROW_P (TREE_TYPE (t))));
 
-    case CPTK_HAS_TRIVIAL_CONSTRUCTOR:
-      type1 = strip_array_types (type1);
-      return (trivial_type_p (type1)
-             || (CLASS_TYPE_P (type1) && TYPE_HAS_TRIVIAL_DFLT (type1)));
-
     case CPTK_HAS_NOTHROW_COPY:
       type1 = strip_array_types (type1);
       return (trait_expr_value (CPTK_HAS_TRIVIAL_COPY, type1, type2)
              || (CLASS_TYPE_P (type1)
                  && classtype_has_nothrow_assign_or_copy_p (type1, false)));
 
+    case CPTK_HAS_TRIVIAL_ASSIGN:
+      /* ??? The standard seems to be missing the "or array of such a class
+        type" wording for this trait.  */
+      type1 = strip_array_types (type1);
+      return (!CP_TYPE_CONST_P (type1) && type_code1 != REFERENCE_TYPE
+             && (trivial_type_p (type1)
+                   || (CLASS_TYPE_P (type1)
+                       && TYPE_HAS_TRIVIAL_COPY_ASSIGN (type1))));
+
+    case CPTK_HAS_TRIVIAL_CONSTRUCTOR:
+      type1 = strip_array_types (type1);
+      return (trivial_type_p (type1)
+             || (CLASS_TYPE_P (type1) && TYPE_HAS_TRIVIAL_DFLT (type1)));
+
     case CPTK_HAS_TRIVIAL_COPY:
       /* ??? The standard seems to be missing the "or array of such a class
         type" wording for this trait.  */
@@ -12375,18 +12375,21 @@ trait_expr_value (cp_trait_kind kind, tree type1, tree type2)
              || (CLASS_TYPE_P (type1)
                  && TYPE_HAS_TRIVIAL_DESTRUCTOR (type1)));
 
-    case CPTK_HAS_VIRTUAL_DESTRUCTOR:
-      return type_has_virtual_destructor (type1);
-
     case CPTK_HAS_UNIQUE_OBJ_REPRESENTATIONS:
       return type_has_unique_obj_representations (type1);
 
+    case CPTK_HAS_VIRTUAL_DESTRUCTOR:
+      return type_has_virtual_destructor (type1);
+
     case CPTK_IS_ABSTRACT:
       return ABSTRACT_CLASS_TYPE_P (type1);
 
     case CPTK_IS_AGGREGATE:
       return CP_AGGREGATE_TYPE_P (type1);
 
+    case CPTK_IS_ASSIGNABLE:
+      return is_xible (MODIFY_EXPR, type1, type2);
+
     case CPTK_IS_BASE_OF:
       return (NON_UNION_CLASS_TYPE_P (type1) && NON_UNION_CLASS_TYPE_P (type2)
              && (same_type_ignoring_top_level_qualifiers_p (type1, type2)
@@ -12395,6 +12398,12 @@ trait_expr_value (cp_trait_kind kind, tree type1, tree type2)
     case CPTK_IS_CLASS:
       return NON_UNION_CLASS_TYPE_P (type1);
 
+    case CPTK_IS_CONSTRUCTIBLE:
+      return is_xible (INIT_EXPR, type1, type2);
+
+    case CPTK_IS_CONVERTIBLE:
+      return is_convertible (type1, type2);
+
     case CPTK_IS_EMPTY:
       return NON_UNION_CLASS_TYPE_P (type1) && CLASSTYPE_EMPTY_P (type1);
 
@@ -12410,6 +12419,15 @@ trait_expr_value (cp_trait_kind kind, tree type1, tree type2)
     case CPTK_IS_LITERAL_TYPE:
       return literal_type_p (type1);
 
+    case CPTK_IS_NOTHROW_ASSIGNABLE:
+      return is_nothrow_xible (MODIFY_EXPR, type1, type2);
+
+    case CPTK_IS_NOTHROW_CONSTRUCTIBLE:
+      return is_nothrow_xible (INIT_EXPR, type1, type2);
+
+    case CPTK_IS_NOTHROW_CONVERTIBLE:
+      return is_nothrow_convertible (type1, type2);
+
     case CPTK_IS_POINTER_INTERCONVERTIBLE_BASE_OF:
       return pointer_interconvertible_base_of_p (type1, type2);
 
@@ -12440,24 +12458,6 @@ trait_expr_value (cp_trait_kind kind, tree type1, tree type2)
     case CPTK_IS_UNION:
       return type_code1 == UNION_TYPE;
 
-    case CPTK_IS_ASSIGNABLE:
-      return is_xible (MODIFY_EXPR, type1, type2);
-
-    case CPTK_IS_CONSTRUCTIBLE:
-      return is_xible (INIT_EXPR, type1, type2);
-
-    case CPTK_IS_NOTHROW_ASSIGNABLE:
-      return is_nothrow_xible (MODIFY_EXPR, type1, type2);
-
-    case CPTK_IS_NOTHROW_CONSTRUCTIBLE:
-      return is_nothrow_xible (INIT_EXPR, type1, type2);
-
-    case CPTK_IS_CONVERTIBLE:
-      return is_convertible (type1, type2);
-
-    case CPTK_IS_NOTHROW_CONVERTIBLE:
-      return is_nothrow_convertible (type1, type2);
-
     case CPTK_REF_CONSTRUCTS_FROM_TEMPORARY:
       return ref_xes_from_temporary (type1, type2, /*direct_init=*/true);
 
@@ -12570,9 +12570,9 @@ finish_trait_expr (location_t loc, cp_trait_kind kind, tree type1, tree type2)
        return error_mark_node;
       break;
 
+    case CPTK_IS_ABSTRACT:
     case CPTK_IS_EMPTY:
     case CPTK_IS_POLYMORPHIC:
-    case CPTK_IS_ABSTRACT:
     case CPTK_HAS_VIRTUAL_DESTRUCTOR:
       if (!check_trait_type (type1, /* kind = */ 3))
        return error_mark_node;
@@ -12592,12 +12592,12 @@ finish_trait_expr (location_t loc, cp_trait_kind kind, tree type1, tree type2)
        return error_mark_node;
       break;
 
-    case CPTK_IS_TRIVIALLY_ASSIGNABLE:
-    case CPTK_IS_TRIVIALLY_CONSTRUCTIBLE:
+    case CPTK_IS_CONVERTIBLE:
     case CPTK_IS_NOTHROW_ASSIGNABLE:
     case CPTK_IS_NOTHROW_CONSTRUCTIBLE:
-    case CPTK_IS_CONVERTIBLE:
     case CPTK_IS_NOTHROW_CONVERTIBLE:
+    case CPTK_IS_TRIVIALLY_ASSIGNABLE:
+    case CPTK_IS_TRIVIALLY_CONSTRUCTIBLE:
     case CPTK_REF_CONSTRUCTS_FROM_TEMPORARY:
     case CPTK_REF_CONVERTS_FROM_TEMPORARY:
       if (!check_trait_type (type1)
@@ -12616,8 +12616,8 @@ 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_SAME:
+    case CPTK_IS_UNION:
       break;
 
     case CPTK_IS_LAYOUT_COMPATIBLE:
@@ -12680,25 +12680,25 @@ finish_trait_type (cp_trait_kind kind, tree type1, tree type2,
 
   switch (kind)
     {
-    case CPTK_UNDERLYING_TYPE:
-      return finish_underlying_type (type1);
-
     case CPTK_REMOVE_CV:
       return cv_unqualified (type1);
 
-    case CPTK_REMOVE_REFERENCE:
+    case CPTK_REMOVE_CVREF:
       if (TYPE_REF_P (type1))
        type1 = TREE_TYPE (type1);
-      return type1;
+      return cv_unqualified (type1);
 
-    case CPTK_REMOVE_CVREF:
+    case CPTK_REMOVE_REFERENCE:
       if (TYPE_REF_P (type1))
        type1 = TREE_TYPE (type1);
-      return cv_unqualified (type1);
+      return type1;
 
     case CPTK_TYPE_PACK_ELEMENT:
       return finish_type_pack_element (type1, type2, complain);
 
+    case CPTK_UNDERLYING_TYPE:
+      return finish_underlying_type (type1);
+
 #define DEFTRAIT_EXPR(CODE, NAME, ARITY) \
     case CPTK_##CODE:
 #include "cp-trait.def"
index f343e153e56c444af0e1cf776adb27a479ff2186..2223f08a6285c0621e58e6f96a8d767dcde36ae9 100644 (file)
@@ -8,9 +8,21 @@
 #if !__has_builtin (__builtin_bit_cast)
 # error "__has_builtin (__builtin_bit_cast) failed"
 #endif
+#if !__has_builtin (__builtin_is_constant_evaluated)
+# error "__has_builtin (__builtin_is_constant_evaluated) failed"
+#endif
+#if !__has_builtin (__builtin_is_corresponding_member)
+# error "__has_builtin (__builtin_is_corresponding_member) failed"
+#endif
+#if !__has_builtin (__builtin_is_pointer_interconvertible_with_class)
+# error "__has_builtin (__builtin_is_pointer_interconvertible_with_class) failed"
+#endif
 #if !__has_builtin (__builtin_launder)
 # error "__has_builtin (__builtin_launder) failed"
 #endif
+#if !__has_builtin (__builtin_source_location)
+# error "__has_builtin (__builtin_source_location) failed"
+#endif
 #if !__has_builtin (__has_nothrow_assign)
 # error "__has_builtin (__has_nothrow_assign) failed"
 #endif
 #if !__has_builtin (__is_aggregate)
 # error "__has_builtin (__is_aggregate) failed"
 #endif
+#if !__has_builtin (__is_assignable)
+# error "__has_builtin (__is_assignable) failed"
+#endif
 #if !__has_builtin (__is_base_of)
 # error "__has_builtin (__is_base_of) failed"
 #endif
 #if !__has_builtin (__is_class)
 # error "__has_builtin (__is_class) failed"
 #endif
+#if !__has_builtin (__is_constructible)
+# error "__has_builtin (__is_constructible) failed"
+#endif
+#if !__has_builtin (__is_convertible)
+# error "__has_builtin (__is_convertible) failed"
+#endif
 #if !__has_builtin (__is_empty)
 # error "__has_builtin (__is_empty) failed"
 #endif
 #if !__has_builtin (__is_literal_type)
 # error "__has_builtin (__is_literal_type) failed"
 #endif
+#if !__has_builtin (__is_nothrow_assignable)
+# error "__has_builtin (__is_nothrow_assignable) failed"
+#endif
+#if !__has_builtin (__is_nothrow_constructible)
+# error "__has_builtin (__is_nothrow_constructible) failed"
+#endif
+#if !__has_builtin (__is_nothrow_convertible)
+# error "__has_builtin (__is_nothrow_convertible) failed"
+#endif
 #if !__has_builtin (__is_pointer_interconvertible_base_of)
 # error "__has_builtin (__is_pointer_interconvertible_base_of) failed"
 #endif
 #if !__has_builtin (__is_union)
 # error "__has_builtin (__is_union) failed"
 #endif
-#if !__has_builtin (__underlying_type)
-# error "__has_builtin (__underlying_type) failed"
-#endif
-#if !__has_builtin (__is_assignable)
-# error "__has_builtin (__is_assignable) failed"
-#endif
-#if !__has_builtin (__is_constructible)
-# error "__has_builtin (__is_constructible) failed"
-#endif
-#if !__has_builtin (__is_nothrow_assignable)
-# error "__has_builtin (__is_nothrow_assignable) failed"
-#endif
-#if !__has_builtin (__is_nothrow_constructible)
-# error "__has_builtin (__is_nothrow_constructible) failed"
-#endif
 #if !__has_builtin (__reference_constructs_from_temporary)
 # error "__has_builtin (__reference_constructs_from_temporary) failed"
 #endif
 #if !__has_builtin (__reference_converts_from_temporary)
 # error "__has_builtin (__reference_converts_from_temporary) failed"
 #endif
-#if !__has_builtin (__builtin_is_constant_evaluated)
-# error "__has_builtin (__builtin_is_constant_evaluated) failed"
-#endif
-#if !__has_builtin (__builtin_source_location)
-# error "__has_builtin (__builtin_source_location) failed"
-#endif
-#if !__has_builtin (__builtin_is_corresponding_member)
-# error "__has_builtin (__builtin_is_corresponding_member) failed"
-#endif
-#if !__has_builtin (__builtin_is_pointer_interconvertible_with_class)
-# error "__has_builtin (__builtin_is_pointer_interconvertible_with_class) failed"
-#endif
-#if !__has_builtin (__is_convertible)
-# error "__has_builtin (__is_convertible) failed"
-#endif
-#if !__has_builtin (__is_nothrow_convertible)
-# error "__has_builtin (__is_nothrow_convertible) failed"
-#endif
 #if !__has_builtin (__remove_cv)
 # error "__has_builtin (__remove_cv) failed"
 #endif
+#if !__has_builtin (__remove_cvref)
+# error "__has_builtin (__remove_cvref) failed"
+#endif
 #if !__has_builtin (__remove_reference)
 # error "__has_builtin (__remove_reference) failed"
 #endif
-#if !__has_builtin (__remove_cvref)
-# error "__has_builtin (__remove_cvref) failed"
+#if !__has_builtin (__underlying_type)
+# error "__has_builtin (__underlying_type) failed"
 #endif