OSDN Git Service

PR c++/14912
authorjason <jason@138bc75d-0d04-0410-961f-82ee72b054a4>
Wed, 29 Jul 2009 20:35:40 +0000 (20:35 +0000)
committerjason <jason@138bc75d-0d04-0410-961f-82ee72b054a4>
Wed, 29 Jul 2009 20:35:40 +0000 (20:35 +0000)
* cp-tree.h (enum tsubst_flags): Add tf_no_class_instantiations.
* error.c (count_non_default_template_args): Pass it.
* pt.c (tsubst) [TYPENAME_TYPE]: Don't complete type if it's set.

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

gcc/cp/ChangeLog
gcc/cp/cp-tree.h
gcc/cp/error.c
gcc/cp/pt.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/template/defarg13.C [new file with mode: 0644]

index 7438541..c52c6da 100644 (file)
@@ -1,3 +1,10 @@
+2009-07-29  Jason Merrill  <jason@redhat.com>
+
+       PR c++/14912
+       * cp-tree.h (enum tsubst_flags): Add tf_no_class_instantiations.
+       * error.c (count_non_default_template_args): Pass it.
+       * pt.c (tsubst) [TYPENAME_TYPE]: Don't complete type if it's set.
+
 2009-07-29  Richard Guenther  <rguenther@suse.de>
 
        PR c++/40834
index 2bc2d62..dcad934 100644 (file)
@@ -3616,6 +3616,8 @@ enum tsubst_flags {
                                    conversion.  */
   tf_no_access_control = 1 << 7, /* Do not perform access checks, even
                                    when issuing other errors.   */
+  /* Do not instantiate classes (used by count_non_default_template_args). */
+  tf_no_class_instantiations = 1 << 8,
   /* Convenient substitution flags combinations.  */
   tf_warning_or_error = tf_warning | tf_error
 };
index c5310ff..25a0580 100644 (file)
@@ -182,7 +182,10 @@ count_non_default_template_args (tree args, tree params)
       if (uses_template_parms (def))
        {
          ++processing_template_decl;
-         def = tsubst_copy_and_build (def, args, tf_none, NULL_TREE, false, true);
+         /* This speculative substitution must not cause any classes to be
+            instantiated that otherwise wouldn't be.  */
+         def = tsubst_copy_and_build (def, args, tf_no_class_instantiations,
+                                      NULL_TREE, false, true);
          --processing_template_decl;
        }
       if (!cp_tree_equal (TREE_VEC_ELT (inner_args, last), def))
index de9f828..ed45324 100644 (file)
@@ -9890,7 +9890,8 @@ tsubst (tree t, tree args, tsubst_flags_t complain, tree in_decl)
               But, such constructs have already been resolved by this
               point, so here CTX really should have complete type, unless
               it's a partial instantiation.  */
-           ctx = complete_type (ctx);
+           if (!(complain & tf_no_class_instantiations))
+             ctx = complete_type (ctx);
            if (!COMPLETE_TYPE_P (ctx))
              {
                if (complain & tf_error)
index 0e55fab..e3b6103 100644 (file)
@@ -1,3 +1,8 @@
+2009-07-29  Jason Merrill  <jason@redhat.com>
+
+       PR c++/14912
+       * g++.dg/template/defarg13.C: New.
+
 2009-07-29  Richard Guenther  <rguenther@suse.de>
 
        PR c++/40834
diff --git a/gcc/testsuite/g++.dg/template/defarg13.C b/gcc/testsuite/g++.dg/template/defarg13.C
new file mode 100644 (file)
index 0000000..ba2980b
--- /dev/null
@@ -0,0 +1,19 @@
+// PR c++/14912
+// Bug: We were instantiating A<B> in order to compare it to the matching
+// argument for C<B,B>, which fails.
+
+template <class T>
+struct A
+{
+  typedef typename T::F F;
+};
+
+struct B { };
+
+template <class T, class U = typename A<T>::F >
+struct C
+{
+  typename T::F f;             // { dg-error "no type" }
+};
+
+C<B, B> c;                     // { dg-message "instantiated" }