* [pushed] c++: variable template array of unknown bound [PR113638]
@ 2024-02-02 3:22 Jason Merrill
0 siblings, 0 replies; only message in thread
From: Jason Merrill @ 2024-02-02 3:22 UTC (permalink / raw)
To: gcc-patches
Tested x86_64-pc-linux-gnu, applying to trunk.
-- 8< --
When we added variable templates, we didn't extend the VAR_HAD_UNKNOWN_BOUND
handling for class template static data members to handle them as well.
PR c++/113638
gcc/cp/ChangeLog:
* cp-tree.h: Adjust comment.
* pt.cc (instantiate_template): Set VAR_HAD_UNKNOWN_BOUND for
variable template.
gcc/testsuite/ChangeLog:
* g++.dg/cpp1y/var-templ-array1.C: New test.
---
gcc/cp/cp-tree.h | 2 +-
gcc/cp/pt.cc | 13 ++++++++++---
gcc/testsuite/g++.dg/cpp1y/var-templ-array1.C | 7 +++++++
3 files changed, 18 insertions(+), 4 deletions(-)
create mode 100644 gcc/testsuite/g++.dg/cpp1y/var-templ-array1.C
diff --git a/gcc/cp/cp-tree.h b/gcc/cp/cp-tree.h
index f46b448ce0d..969c7239c97 100644
--- a/gcc/cp/cp-tree.h
+++ b/gcc/cp/cp-tree.h
@@ -3251,7 +3251,7 @@ struct GTY(()) lang_decl {
#define DECL_CONV_FN_TYPE(FN) \
TREE_TYPE ((gcc_checking_assert (DECL_CONV_FN_P (FN)), DECL_NAME (FN)))
-/* Nonzero if NODE, a static data member, was declared in its class as an
+/* Nonzero if NODE, a templated variable, was declared as an
array of unknown bound. */
#define VAR_HAD_UNKNOWN_BOUND(NODE) \
(DECL_LANG_SPECIFIC (VAR_DECL_CHECK (NODE)) \
diff --git a/gcc/cp/pt.cc b/gcc/cp/pt.cc
index 16febb1ba7f..9d30a271713 100644
--- a/gcc/cp/pt.cc
+++ b/gcc/cp/pt.cc
@@ -22105,9 +22105,16 @@ instantiate_template (tree tmpl, tree orig_args, tsubst_flags_t complain)
DECL_TI_TEMPLATE (fndecl) = tmpl;
DECL_TI_ARGS (fndecl) = targ_ptr;
if (VAR_P (pattern))
- /* Now that we we've formed this variable template specialization,
- remember the result of most_specialized_partial_spec for it. */
- TI_PARTIAL_INFO (DECL_TEMPLATE_INFO (fndecl)) = partial_ti;
+ {
+ /* Now that we we've formed this variable template specialization,
+ remember the result of most_specialized_partial_spec for it. */
+ TI_PARTIAL_INFO (DECL_TEMPLATE_INFO (fndecl)) = partial_ti;
+
+ /* And remember if the variable was declared with []. */
+ if (TREE_CODE (TREE_TYPE (fndecl)) == ARRAY_TYPE
+ && TYPE_DOMAIN (TREE_TYPE (fndecl)) == NULL_TREE)
+ SET_VAR_HAD_UNKNOWN_BOUND (fndecl);
+ }
fndecl = register_specialization (fndecl, gen_tmpl, targ_ptr, false, hash);
if (fndecl == error_mark_node)
diff --git a/gcc/testsuite/g++.dg/cpp1y/var-templ-array1.C b/gcc/testsuite/g++.dg/cpp1y/var-templ-array1.C
new file mode 100644
index 00000000000..b0ff7e74556
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp1y/var-templ-array1.C
@@ -0,0 +1,7 @@
+// PR c++/113638
+// { dg-do compile { target c++14 } }
+
+template<int ...Is>
+constexpr int my_array[]{Is...};
+constexpr auto t1 = my_array<2>;
+static_assert(sizeof(my_array<1>) == sizeof(int) * 1, "");
base-commit: e0701f8f7b6dcddb299eb5345e510cf9ea419150
--
2.39.3
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2024-02-02 3:22 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-02-02 3:22 [pushed] c++: variable template array of unknown bound [PR113638] Jason Merrill
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).