From c6a38536f205e0723600d54bce3aaf05ec107161 Mon Sep 17 00:00:00 2001 From: Jason Merrill Date: Tue, 6 Jan 2015 15:44:51 -0500 Subject: [PATCH] re PR c++/64455 (A constexpr variable template can't be used with enable_if) PR c++/64455 * pt.c (type_dependent_expression_p): Handle variable templates. * constexpr.c (potential_constant_expression_1): Use it. From-SVN: r219268 --- gcc/cp/ChangeLog | 4 ++++ gcc/cp/constexpr.c | 2 +- gcc/cp/pt.c | 8 ++++++++ gcc/testsuite/g++.dg/cpp1y/var-templ21.C | 25 ++++++++++++++++++++++++ 4 files changed, 38 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/g++.dg/cpp1y/var-templ21.C diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 604b518d607..e5e54eae6f0 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,5 +1,9 @@ 2015-01-06 Jason Merrill + PR c++/64455 + * pt.c (type_dependent_expression_p): Handle variable templates. + * constexpr.c (potential_constant_expression_1): Use it. + PR c++/64487 * semantics.c (finish_offsetof): Handle templates here. * parser.c (cp_parser_builtin_offsetof): Not here. diff --git a/gcc/cp/constexpr.c b/gcc/cp/constexpr.c index ee796dfc913..4da263e4367 100644 --- a/gcc/cp/constexpr.c +++ b/gcc/cp/constexpr.c @@ -3882,7 +3882,7 @@ potential_constant_expression_1 (tree t, bool want_rval, bool strict, || !CP_TYPE_CONST_NON_VOLATILE_P (TREE_TYPE (t)) || !DECL_INITIALIZED_BY_CONSTANT_EXPRESSION_P (t)) && !var_in_constexpr_fn (t) - && !dependent_type_p (TREE_TYPE (t))) + && !type_dependent_expression_p (t)) { if (flags & tf_error) non_const_var_error (t); diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c index 15645b98c1c..de2f6a4a33c 100644 --- a/gcc/cp/pt.c +++ b/gcc/cp/pt.c @@ -21369,6 +21369,14 @@ type_dependent_expression_p (tree expression) && DECL_INITIAL (expression)) return true; + /* A variable template specialization is type-dependent if it has any + dependent template arguments. */ + if (VAR_P (expression) + && DECL_LANG_SPECIFIC (expression) + && DECL_TEMPLATE_INFO (expression) + && variable_template_p (DECL_TI_TEMPLATE (expression))) + return any_dependent_template_arguments_p (DECL_TI_ARGS (expression)); + if (TREE_TYPE (expression) == unknown_type_node) { if (TREE_CODE (expression) == ADDR_EXPR) diff --git a/gcc/testsuite/g++.dg/cpp1y/var-templ21.C b/gcc/testsuite/g++.dg/cpp1y/var-templ21.C new file mode 100644 index 00000000000..a7b08995836 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp1y/var-templ21.C @@ -0,0 +1,25 @@ +// PR c++/64455 +// { dg-do compile { target c++14 } } + +template +constexpr bool IsType = true; + +template struct Test +{ +}; + +template +struct Test +{ + typedef T type; +}; + +template +struct X { + typedef typename Test,T>::type type; +}; + +int main() +{ + X::type t; +} -- 2.30.2