Hi!

This is basically Marek's PR114479 r14-9759 __is_array fix applied to
__is_bounded_array as well.  Similarly to that trait, when not using
the builtin it returned false for zero sized arrays but when using
the builtin it returns true.

Fixed thusly, bootstrapped/regtested on x86_64-linux and i686-linux, ok for
trunk?
Do we want to backport this to 14.3 or not?

2025-01-28  Jakub Jelinek  <ja...@redhat.com>

        PR c++/118655
        * semantics.cc (trait_expr_value) <case CPTK_IS_BOUNDED_ARRAY>: Return
        false for zero-sized arrays.
    
        * g++.dg/ext/is_bounded_array.C: Extend.

--- gcc/cp/semantics.cc.jj      2025-01-17 11:29:33.616689665 +0100
+++ gcc/cp/semantics.cc 2025-01-27 12:21:11.439367867 +0100
@@ -13165,7 +13165,14 @@ trait_expr_value (cp_trait_kind kind, tr
                  || DERIVED_FROM_P (type1, type2)));
 
     case CPTK_IS_BOUNDED_ARRAY:
-      return type_code1 == ARRAY_TYPE && TYPE_DOMAIN (type1);
+      return (type_code1 == ARRAY_TYPE
+             && TYPE_DOMAIN (type1)
+             /* We don't want to report T[0] as being a bounded array type.
+                This is for compatibility with an implementation of
+                std::is_bounded_array by template argument deduction, because
+                compute_array_index_type_loc rejects a zero-size array
+                in SFINAE context.  */
+             && !(TYPE_SIZE (type1) && integer_zerop (TYPE_SIZE (type1))));
 
     case CPTK_IS_CLASS:
       return NON_UNION_CLASS_TYPE_P (type1);
--- gcc/testsuite/g++.dg/ext/is_bounded_array.C.jj      2023-12-22 
12:26:14.917893636 +0100
+++ gcc/testsuite/g++.dg/ext/is_bounded_array.C 2025-01-27 12:34:18.400549388 
+0100
@@ -1,4 +1,5 @@
 // { dg-do compile { target c++11 } }
+// { dg-options "" }
 
 #define SA(X) static_assert((X),#X)
 
@@ -14,21 +15,34 @@
 
 class ClassType { };
 
+constexpr int sz0 = 0;
+constexpr int sz2 = 2;
+
 SA_TEST_CATEGORY(__is_bounded_array, int[2], true);
 SA_TEST_CATEGORY(__is_bounded_array, int[], false);
+SA_TEST_CATEGORY(__is_bounded_array, int[0], false);
 SA_TEST_CATEGORY(__is_bounded_array, int[2][3], true);
 SA_TEST_CATEGORY(__is_bounded_array, int[][3], false);
+SA_TEST_CATEGORY(__is_bounded_array, int[0][3], false);
+SA_TEST_CATEGORY(__is_bounded_array, int[3][0], false);
 SA_TEST_CATEGORY(__is_bounded_array, float*[2], true);
 SA_TEST_CATEGORY(__is_bounded_array, float*[], false);
 SA_TEST_CATEGORY(__is_bounded_array, float*[2][3], true);
 SA_TEST_CATEGORY(__is_bounded_array, float*[][3], false);
 SA_TEST_CATEGORY(__is_bounded_array, ClassType[2], true);
 SA_TEST_CATEGORY(__is_bounded_array, ClassType[], false);
+SA_TEST_CATEGORY(__is_bounded_array, ClassType[0], false);
 SA_TEST_CATEGORY(__is_bounded_array, ClassType[2][3], true);
 SA_TEST_CATEGORY(__is_bounded_array, ClassType[][3], false);
+SA_TEST_CATEGORY(__is_bounded_array, ClassType[0][3], false);
+SA_TEST_CATEGORY(__is_bounded_array, ClassType[2][0], false);
+SA_TEST_CATEGORY(__is_bounded_array, int[sz2], true);
+SA_TEST_CATEGORY(__is_bounded_array, int[sz0], false);
 SA_TEST_CATEGORY(__is_bounded_array, int(*)[2], false);
 SA_TEST_CATEGORY(__is_bounded_array, int(*)[], false);
+SA_TEST_CATEGORY(__is_bounded_array, int(*)[0], false);
 SA_TEST_CATEGORY(__is_bounded_array, int(&)[2], false);
+SA_TEST_CATEGORY(__is_bounded_array, int(&)[0], false);
 SA_TEST_FN(__is_bounded_array, int(&)[], false);
 
 // Sanity check.

        Jakub

Reply via email to