summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPatrick Palka <ppalka@redhat.com>2024-06-25 10:42:21 -0400
committerDongkyun Son <dongkyun.s@samsung.com>2024-06-28 20:34:49 +0900
commit191f32cad0d99d3b43f4fc1649470c7fa39e4034 (patch)
tree6e645b4e1fe53de003b277bb2f30b7e54c632cd3
parentdafd6a8f693271d0b9f8c25eef55158036016380 (diff)
downloadgcc-accepted/tizen_base_toolchain.tar.gz
gcc-accepted/tizen_base_toolchain.tar.bz2
gcc-accepted/tizen_base_toolchain.zip
For a non-dependent array variable of unknown bound, it seems we need to try instantiating its definition upon use in a template context for sake of proper checking and typing of the overall expression, like we do for function specializations with deduced return type. PR c++/115358 gcc/cp/ChangeLog: * decl2.cc (mark_used): Call maybe_instantiate_decl for an array variable with unknown bound. * semantics.cc (finish_decltype_type): Remove now redundant handling of array variables with unknown bound. * typeck.cc (cxx_sizeof_expr): Likewise. gcc/testsuite/ChangeLog: * g++.dg/template/array37.C: New test. cherry-picked from commit e3915c1ad56591cbd68229a64c941c38330abd69 Change-Id: I67805511bb4b31509ddfdb6eaa581c71e6e14c5a Reviewed-by: Jason Merrill <jason@redhat.com>
-rw-r--r--gcc/cp/decl2.cc2
-rw-r--r--gcc/cp/semantics.cc7
-rw-r--r--gcc/cp/typeck.cc7
-rw-r--r--gcc/testsuite/g++.dg/template/array37.C14
4 files changed, 16 insertions, 14 deletions
diff --git a/gcc/cp/decl2.cc b/gcc/cp/decl2.cc
index 806a2a4bc69..7c365b3668a 100644
--- a/gcc/cp/decl2.cc
+++ b/gcc/cp/decl2.cc
@@ -5951,6 +5951,8 @@ mark_used (tree decl, tsubst_flags_t complain /* = tf_warning_or_error */)
find out its type. For OpenMP user defined reductions, we need them
instantiated for reduction clauses which inline them by hand directly. */
if (undeduced_auto_decl (decl)
+ || (VAR_P (decl)
+ && VAR_HAD_UNKNOWN_BOUND (decl))
|| (TREE_CODE (decl) == FUNCTION_DECL
&& DECL_OMP_DECLARE_REDUCTION_P (decl)))
maybe_instantiate_decl (decl);
diff --git a/gcc/cp/semantics.cc b/gcc/cp/semantics.cc
index 02c7c1bf5a4..7351657531d 100644
--- a/gcc/cp/semantics.cc
+++ b/gcc/cp/semantics.cc
@@ -11837,13 +11837,6 @@ finish_decltype_type (tree expr, bool id_expression_or_member_access_p,
return error_mark_node;
}
- /* To get the size of a static data member declared as an array of
- unknown bound, we need to instantiate it. */
- if (VAR_P (expr)
- && VAR_HAD_UNKNOWN_BOUND (expr)
- && DECL_TEMPLATE_INSTANTIATION (expr))
- instantiate_decl (expr, /*defer_ok*/true, /*expl_inst_mem*/false);
-
if (id_expression_or_member_access_p)
{
/* If e is an id-expression or a class member access (5.2.5
diff --git a/gcc/cp/typeck.cc b/gcc/cp/typeck.cc
index a25f8622651..67c754dd578 100644
--- a/gcc/cp/typeck.cc
+++ b/gcc/cp/typeck.cc
@@ -2125,13 +2125,6 @@ cxx_sizeof_expr (location_t loc, tree e, tsubst_flags_t complain)
location_t e_loc = cp_expr_loc_or_loc (e, loc);
STRIP_ANY_LOCATION_WRAPPER (e);
- /* To get the size of a static data member declared as an array of
- unknown bound, we need to instantiate it. */
- if (VAR_P (e)
- && VAR_HAD_UNKNOWN_BOUND (e)
- && DECL_TEMPLATE_INSTANTIATION (e))
- instantiate_decl (e, /*defer_ok*/true, /*expl_inst_mem*/false);
-
if (TREE_CODE (e) == PARM_DECL
&& DECL_ARRAY_PARAMETER_P (e)
&& (complain & tf_warning))
diff --git a/gcc/testsuite/g++.dg/template/array37.C b/gcc/testsuite/g++.dg/template/array37.C
new file mode 100644
index 00000000000..c5c11663a4d
--- /dev/null
+++ b/gcc/testsuite/g++.dg/template/array37.C
@@ -0,0 +1,14 @@
+// PR c++/115358
+
+template<class T>
+struct A { static int STR[]; };
+
+template<class T>
+int A<T>::STR[] = {1,2,3};
+
+void f(int(&)[3]);
+
+template<class T>
+void g() {
+ f(A<int>::STR); // { dg-bogus "int []" }
+}