PR c++/63889
authorjason <jason@138bc75d-0d04-0410-961f-82ee72b054a4>
Tue, 27 Jan 2015 19:16:51 +0000 (19:16 +0000)
committerjason <jason@138bc75d-0d04-0410-961f-82ee72b054a4>
Tue, 27 Jan 2015 19:16:51 +0000 (19:16 +0000)
* pt.c (finish_template_variable): Move from semantics.c.
Handle multiple template arg levels.  Handle coercion here.
(lookup_template_variable): Not here.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@220183 138bc75d-0d04-0410-961f-82ee72b054a4

gcc/cp/ChangeLog
gcc/cp/pt.c
gcc/cp/semantics.c
gcc/testsuite/g++.dg/cpp1y/var-templ22.C [new file with mode: 0644]

index ac91652..b914f4b 100644 (file)
@@ -1,3 +1,10 @@
+2015-01-27  Jason Merrill  <jason@redhat.com>
+
+       PR c++/63889
+       * pt.c (finish_template_variable): Move from semantics.c.
+       Handle multiple template arg levels.  Handle coercion here.
+       (lookup_template_variable): Not here.
+
 2015-01-23  Jason Merrill  <jason@redhat.com>
 
        PR c++/64314
index bc26530..d377daa 100644 (file)
@@ -8091,13 +8091,28 @@ tree
 lookup_template_variable (tree templ, tree arglist)
 {
   tree type = unknown_type_node;
-  tsubst_flags_t complain = tf_warning_or_error;
-  tree parms = INNERMOST_TEMPLATE_PARMS (DECL_TEMPLATE_PARMS (templ));
-  arglist = coerce_template_parms (parms, arglist, templ, complain,
-                                  /*req_all*/true, /*use_default*/true);
   return build2 (TEMPLATE_ID_EXPR, type, templ, arglist);
 }
 
+/* Instantiate a variable declaration from a TEMPLATE_ID_EXPR for use. */
+
+tree
+finish_template_variable (tree var)
+{
+  tree templ = TREE_OPERAND (var, 0);
+
+  tree arglist = TREE_OPERAND (var, 1);
+  tree tmpl_args = DECL_TI_ARGS (DECL_TEMPLATE_RESULT (templ));
+  arglist = add_outermost_template_args (tmpl_args, arglist);
+
+  tree parms = DECL_TEMPLATE_PARMS (templ);
+  tsubst_flags_t complain = tf_warning_or_error;
+  arglist = coerce_innermost_template_parms (parms, arglist, templ, complain,
+                                            /*req_all*/true,
+                                            /*use_default*/true);
+
+  return instantiate_template (templ, arglist, complain);
+}
 \f
 struct pair_fn_data
 {
index 915048d..75aa501 100644 (file)
@@ -2454,15 +2454,6 @@ finish_call_expr (tree fn, vec<tree, va_gc> **args, bool disallow_virtual,
   return result;
 }
 
-/* Instantiate a variable declaration from a TEMPLATE_ID_EXPR for use. */
-
-tree
-finish_template_variable (tree var)
-{
-  return instantiate_template (TREE_OPERAND (var, 0), TREE_OPERAND (var, 1),
-                               tf_error);
-}
-
 /* Finish a call to a postfix increment or decrement or EXPR.  (Which
    is indicated by CODE, which should be POSTINCREMENT_EXPR or
    POSTDECREMENT_EXPR.)  */
diff --git a/gcc/testsuite/g++.dg/cpp1y/var-templ22.C b/gcc/testsuite/g++.dg/cpp1y/var-templ22.C
new file mode 100644 (file)
index 0000000..9ddc925
--- /dev/null
@@ -0,0 +1,14 @@
+// PR c++/63889
+// { dg-do compile { target c++14 } }
+
+template<class T>
+struct A
+{
+  template<class>
+  static constexpr bool is_ok = true;
+
+  template<bool v = is_ok<T>>
+  A(T) { }
+};
+
+A<int> p(42);