https://gcc.gnu.org/g:3a6ddbf7b241e1cd9f73495ea373b0a12015bb07

commit r15-7263-g3a6ddbf7b241e1cd9f73495ea373b0a12015bb07
Author: Jakub Jelinek <ja...@redhat.com>
Date:   Wed Jan 29 09:32:04 2025 +0100

    c++: Return false from __is_bounded_array for zero-sized arrays [PR118655]
    
    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.
    
    2025-01-29  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.

Diff:
---
 gcc/cp/semantics.cc                         |  9 ++++++++-
 gcc/testsuite/g++.dg/ext/is_bounded_array.C | 14 ++++++++++++++
 2 files changed, 22 insertions(+), 1 deletion(-)

diff --git a/gcc/cp/semantics.cc b/gcc/cp/semantics.cc
index e891319f9a99..ad9864c3a91a 100644
--- a/gcc/cp/semantics.cc
+++ b/gcc/cp/semantics.cc
@@ -13165,7 +13165,14 @@ trait_expr_value (cp_trait_kind kind, tree type1, tree 
type2)
                  || 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);
diff --git a/gcc/testsuite/g++.dg/ext/is_bounded_array.C 
b/gcc/testsuite/g++.dg/ext/is_bounded_array.C
index b5fe435de957..63cd4f89091b 100644
--- a/gcc/testsuite/g++.dg/ext/is_bounded_array.C
+++ b/gcc/testsuite/g++.dg/ext/is_bounded_array.C
@@ -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.

Reply via email to