* C++ PATCH for variable templates in pack expansions
@ 2015-07-10 21:33 Jason Merrill
0 siblings, 0 replies; only message in thread
From: Jason Merrill @ 2015-07-10 21:33 UTC (permalink / raw)
To: gcc-patches List
[-- Attachment #1: Type: text/plain, Size: 166 bytes --]
Looking at the concepts work led me to notice this bug: we weren't
finding packs used only in variable template-ids.
Tested x86_64-pc-linux-gnu, applying to trunk.
[-- Attachment #2: var-exp.patch --]
[-- Type: text/x-patch, Size: 2571 bytes --]
commit 29ae93b90171f5202ec1de7507b77d09b2dff643
Author: Jason Merrill <jason@redhat.com>
Date: Fri Jul 10 15:27:11 2015 -0400
* pt.c (find_parameter_packs_r): Handle variable templates.
(variable_template_specialization_p): New.
* cp-tree.h: Declare it.
diff --git a/gcc/cp/cp-tree.h b/gcc/cp/cp-tree.h
index d383612..8450e9b 100644
--- a/gcc/cp/cp-tree.h
+++ b/gcc/cp/cp-tree.h
@@ -5771,6 +5771,7 @@ extern bool reregister_specialization (tree, tree, tree);
extern tree instantiate_non_dependent_expr (tree);
extern tree instantiate_non_dependent_expr_sfinae (tree, tsubst_flags_t);
extern tree instantiate_non_dependent_expr_internal (tree, tsubst_flags_t);
+extern bool variable_template_specialization_p (tree);
extern bool alias_type_or_template_p (tree);
extern bool alias_template_specialization_p (const_tree);
extern bool dependent_alias_template_spec_p (const_tree);
diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c
index 63907ce..8c72a61 100644
--- a/gcc/cp/pt.c
+++ b/gcc/cp/pt.c
@@ -3245,6 +3245,13 @@ find_parameter_packs_r (tree *tp, int *walk_subtrees, void* data)
ppd, ppd->visited);
*walk_subtrees = 0;
}
+ else if (variable_template_specialization_p (t))
+ {
+ cp_walk_tree (&DECL_TI_ARGS (t),
+ find_parameter_packs_r,
+ ppd, ppd->visited);
+ *walk_subtrees = 0;
+ }
break;
case BASES:
@@ -5351,6 +5358,17 @@ instantiate_non_dependent_expr (tree expr)
return instantiate_non_dependent_expr_sfinae (expr, tf_error);
}
+/* True iff T is a specialization of a variable template. */
+
+bool
+variable_template_specialization_p (tree t)
+{
+ if (!VAR_P (t) || !DECL_LANG_SPECIFIC (t) || !DECL_TEMPLATE_INFO (t))
+ return false;
+ tree tmpl = DECL_TI_TEMPLATE (t);
+ return variable_template_p (tmpl);
+}
+
/* Return TRUE iff T is a type alias, a TEMPLATE_DECL for an alias
template declaration, or a TYPE_DECL for an alias declaration. */
diff --git a/gcc/testsuite/g++.dg/cpp1y/var-templ33.C b/gcc/testsuite/g++.dg/cpp1y/var-templ33.C
new file mode 100644
index 0000000..53c6db2
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp1y/var-templ33.C
@@ -0,0 +1,20 @@
+// Test for variable templates in pack expansion
+// { dg-do compile { target c++14 } }
+
+template <int I> const int Val = I;
+
+constexpr int f () { return 0; }
+template <class T, class ...Ts>
+constexpr int f(T t, Ts... ts)
+{
+ return t + f(ts...);
+}
+
+template <int... Is>
+constexpr int g()
+{
+ return f(Val<Is>...);
+}
+
+#define SA(X) static_assert((X),#X)
+SA((g<1,2,3,4>() == 1+2+3+4));
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2015-07-10 21:33 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-07-10 21:33 C++ PATCH for variable templates in pack expansions 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).