aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJakub Jelinek <jakub@redhat.com>2025-01-29 09:32:04 +0100
committerJakub Jelinek <jakub@gcc.gnu.org>2025-01-29 09:32:04 +0100
commit3a6ddbf7b241e1cd9f73495ea373b0a12015bb07 (patch)
treef6a6dbde7b975dfb04f52bc258ecc4cc24d39bed
parent5d001fa122bf04cfd0611ff7723969a0421b3094 (diff)
downloadgcc-3a6ddbf7b241e1cd9f73495ea373b0a12015bb07.zip
gcc-3a6ddbf7b241e1cd9f73495ea373b0a12015bb07.tar.gz
gcc-3a6ddbf7b241e1cd9f73495ea373b0a12015bb07.tar.bz2
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 <jakub@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.
-rw-r--r--gcc/cp/semantics.cc9
-rw-r--r--gcc/testsuite/g++.dg/ext/is_bounded_array.C14
2 files changed, 22 insertions, 1 deletions
diff --git a/gcc/cp/semantics.cc b/gcc/cp/semantics.cc
index e891319..ad9864c 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 b5fe435..63cd4f8 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.