re PR c++/70543 (wrong non-const error for enable_if and constexpr function)
authorJason Merrill <jason@redhat.com>
Thu, 14 Apr 2016 20:14:44 +0000 (16:14 -0400)
committerJason Merrill <jason@gcc.gnu.org>
Thu, 14 Apr 2016 20:14:44 +0000 (16:14 -0400)
PR c++/70543

* pt.c (value_dependent_expression_p) [VAR_DECL]: A type-dependent
initializer also makes the variable value-dependent.

From-SVN: r234990

gcc/cp/ChangeLog
gcc/cp/pt.c
gcc/testsuite/g++.dg/cpp0x/constexpr-template9.C [new file with mode: 0644]

index cba07aa166aec2555af630fef6f6a26f889eaef6..01f13b73cd25127a96303e78cae090653e8adcc1 100644 (file)
@@ -1,5 +1,9 @@
 2016-04-14  Jason Merrill  <jason@redhat.com>
 
+       PR c++/70543
+       * pt.c (value_dependent_expression_p) [VAR_DECL]: A type-dependent
+       initializer also makes the variable value-dependent.
+
        PR c++/70648
        * constexpr.c (cxx_eval_store_expression): Also copy
        CONSTRUCTOR_NO_IMPLICIT_ZERO.
index d066e559d0c7e56e1855a8fa07c82be32de9d273..4a00530b31215c74733de90d4c1349e4456a80dd 100644 (file)
@@ -22670,6 +22670,7 @@ value_dependent_expression_p (tree expression)
          && (TREE_CODE (DECL_INITIAL (expression)) == TREE_LIST
              /* cp_finish_decl doesn't fold reference initializers.  */
              || TREE_CODE (TREE_TYPE (expression)) == REFERENCE_TYPE
+             || type_dependent_expression_p (DECL_INITIAL (expression))
              || value_dependent_expression_p (DECL_INITIAL (expression))))
        return true;
       return false;
diff --git a/gcc/testsuite/g++.dg/cpp0x/constexpr-template9.C b/gcc/testsuite/g++.dg/cpp0x/constexpr-template9.C
new file mode 100644 (file)
index 0000000..2ca641d
--- /dev/null
@@ -0,0 +1,17 @@
+// PR c++/70543
+// { dg-do compile { target c++11 } }
+
+template <typename>
+struct X
+{
+  template <unsigned int = 0>
+  static constexpr int
+  calc (void)
+  {
+    return 0;
+  }
+
+  static constexpr unsigned int value = calc ();
+
+  char foo[value];
+};