re PR c++/64455 (A constexpr variable template can't be used with enable_if)
authorJason Merrill <jason@redhat.com>
Tue, 6 Jan 2015 20:44:51 +0000 (15:44 -0500)
committerJason Merrill <jason@gcc.gnu.org>
Tue, 6 Jan 2015 20:44:51 +0000 (15:44 -0500)
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
gcc/cp/constexpr.c
gcc/cp/pt.c
gcc/testsuite/g++.dg/cpp1y/var-templ21.C [new file with mode: 0644]

index 604b518d6072ba3f233f41d2a684781144c26e70..e5e54eae6f068687dec5eb9dc23d0c19299eff39 100644 (file)
@@ -1,5 +1,9 @@
 2015-01-06  Jason Merrill  <jason@redhat.com>
 
+       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.
index ee796dfc913dbd756f35d6124918a07b00251612..4da263e43679444d367758273afc2e2aace3c265 100644 (file)
@@ -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);
index 15645b98c1cb2c60d52e49a6b75452a24387ae98..de2f6a4a33c070b1b64c8e9da6bba2a8fcafad05 100644 (file)
@@ -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 (file)
index 0000000..a7b0899
--- /dev/null
@@ -0,0 +1,25 @@
+// PR c++/64455
+// { dg-do compile { target c++14 } }
+
+template<typename Type>
+constexpr bool IsType = true;
+
+template <bool b, class T> struct Test
+{
+};
+
+template <class T>
+struct Test<true, T>
+{
+        typedef T type;
+};
+
+template<class T>
+struct X {
+    typedef typename Test<IsType<T>,T>::type type;
+};
+
+int main()
+{
+   X<int>::type t;
+}