diff options
author | jason <jason@138bc75d-0d04-0410-961f-82ee72b054a4> | 2015-08-06 04:09:49 +0000 |
---|---|---|
committer | jason <jason@138bc75d-0d04-0410-961f-82ee72b054a4> | 2015-08-06 04:09:49 +0000 |
commit | 3af0bf60169cf209d84ace9482603d1ebbe6d0d1 (patch) | |
tree | aa0b1f012984b58472b550899ede0342e48606b3 | |
parent | 417e3ef980fb2afaeb2201735db299f9eb3fb65f (diff) | |
download | gcc-3af0bf60169cf209d84ace9482603d1ebbe6d0d1.tar.gz |
PR c++/66336
* pt.c (find_parameter_packs_r): Handle variable templates.
(variable_template_specialization_p): New.
* cp-tree.h: Declare it.
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/branches/gcc-5-branch@226655 138bc75d-0d04-0410-961f-82ee72b054a4
-rw-r--r-- | gcc/cp/ChangeLog | 5 | ||||
-rw-r--r-- | gcc/cp/cp-tree.h | 1 | ||||
-rw-r--r-- | gcc/cp/pt.c | 18 | ||||
-rw-r--r-- | gcc/testsuite/g++.dg/cpp1y/var-templ33.C | 20 |
4 files changed, 44 insertions, 0 deletions
diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 23b34d7ce1d..059438a1b0a 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,5 +1,10 @@ 2015-08-05 Jason Merrill <jason@redhat.com> + PR c++/66336 + * pt.c (find_parameter_packs_r): Handle variable templates. + (variable_template_specialization_p): New. + * cp-tree.h: Declare it. + * decl.c (start_decl): Don't push the plain VAR_DECL for a variable template. diff --git a/gcc/cp/cp-tree.h b/gcc/cp/cp-tree.h index 4e525e04d5c..3ece2a58f06 100644 --- a/gcc/cp/cp-tree.h +++ b/gcc/cp/cp-tree.h @@ -5762,6 +5762,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 897b0c70dd8..2ab599f9996 100644 --- a/gcc/cp/pt.c +++ b/gcc/cp/pt.c @@ -3222,6 +3222,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: @@ -5323,6 +5330,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 00000000000..53c6db2b974 --- /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)); |