]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
c++: Handle RAW_DATA_CST in unify [PR118390]
authorJakub Jelinek <jakub@redhat.com>
Wed, 15 Jan 2025 17:27:07 +0000 (18:27 +0100)
committerJakub Jelinek <jakub@gcc.gnu.org>
Wed, 15 Jan 2025 17:28:33 +0000 (18:28 +0100)
This patch uses the count_ctor_elements function to fix up
unify deduction of array sizes.

2025-01-15  Jakub Jelinek  <jakub@redhat.com>

PR c++/118390
* cp-tree.h (count_ctor_elements): Declare.
* call.cc (count_ctor_elements): No longer static.
* pt.cc (unify): Use count_ctor_elements instead of
CONSTRUCTOR_NELTS.

* g++.dg/cpp/embed-20.C: New test.
* g++.dg/cpp0x/pr118390.C: New test.

gcc/cp/call.cc
gcc/cp/cp-tree.h
gcc/cp/pt.cc
gcc/testsuite/g++.dg/cpp/embed-20.C [new file with mode: 0644]
gcc/testsuite/g++.dg/cpp0x/pr118390.C [new file with mode: 0644]

index 63be8b58906b35302346c1ff1359d877cbd36331..9e57261cf17d48bc319f6162d7ebf1b5ad4064d6 100644 (file)
@@ -4333,7 +4333,7 @@ has_non_trivial_temporaries (tree expr)
 
 /* Return number of initialized elements in CTOR.  */
 
-static unsigned HOST_WIDE_INT
+unsigned HOST_WIDE_INT
 count_ctor_elements (tree ctor)
 {
   unsigned HOST_WIDE_INT len = 0;
index 2d17c4c77b56770a6fd857d6c526e855462f8643..bb10c7ca053d687337afe66bad9f92616c3d454d 100644 (file)
@@ -6815,6 +6815,7 @@ extern tree type_decays_to                        (tree);
 extern tree extract_call_expr                  (tree);
 extern tree build_trivial_dtor_call            (tree, bool = false);
 extern tristate ref_conv_binds_to_temporary    (tree, tree, bool = false);
+extern unsigned HOST_WIDE_INT count_ctor_elements (tree);
 extern tree build_user_type_conversion         (tree, tree, int,
                                                 tsubst_flags_t);
 extern tree build_new_function_call            (tree, vec<tree, va_gc> **,
index ff0a3a4f7d8108b07f67418bf2426255d39c0e4c..3b6743f2e3af880b10b64d026feca21b8eae8eaf 100644 (file)
@@ -25072,7 +25072,7 @@ unify (tree tparms, tree targs, tree parm, tree arg, int strict,
          && deducible_array_bound (TYPE_DOMAIN (parm)))
        {
          /* Also deduce from the length of the initializer list.  */
-         tree max = size_int (CONSTRUCTOR_NELTS (arg));
+         tree max = size_int (count_ctor_elements (arg));
          tree idx = compute_array_index_type (NULL_TREE, max, tf_none);
          if (idx == error_mark_node)
            return unify_invalid (explain_p);
diff --git a/gcc/testsuite/g++.dg/cpp/embed-20.C b/gcc/testsuite/g++.dg/cpp/embed-20.C
new file mode 100644 (file)
index 0000000..ad70840
--- /dev/null
@@ -0,0 +1,14 @@
+// PR c++/118390
+// { dg-do compile { target c++11 } }
+// { dg-options "" }
+
+template<typename T, int N>
+constexpr int
+foo (const T (&x)[N])
+{
+  return N;
+}
+
+static_assert (foo ({
+  #embed __FILE__ limit (64)
+}) == 64, "");
diff --git a/gcc/testsuite/g++.dg/cpp0x/pr118390.C b/gcc/testsuite/g++.dg/cpp0x/pr118390.C
new file mode 100644 (file)
index 0000000..e5017b0
--- /dev/null
@@ -0,0 +1,23 @@
+// PR c++/118390
+// { dg-do compile { target c++11 } }
+// { dg-options "" }
+
+template<typename T, int N>
+constexpr int
+foo (const T (&x)[N])
+{
+  return N;
+}
+
+static_assert (foo ({
+  1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16,
+  1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16,
+  1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16,
+  1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16,
+  1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16,
+  1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16,
+  1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16,
+  1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16,
+  1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16,
+  1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16,
+}) == 160, "");