aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorMark Mitchell <mark@codesourcery.com>2002-04-13 01:33:23 +0000
committerMark Mitchell <mmitchel@gcc.gnu.org>2002-04-13 01:33:23 +0000
commit9928a3d53a7d5d2a9a2ac1d9012f86b475d1c4b6 (patch)
treeeaf1462047a20855fe42368124b60aff8c336af9 /gcc
parentc740732f62c3784700fa3d819af4f408f768dd48 (diff)
downloadgcc-9928a3d53a7d5d2a9a2ac1d9012f86b475d1c4b6.zip
gcc-9928a3d53a7d5d2a9a2ac1d9012f86b475d1c4b6.tar.gz
gcc-9928a3d53a7d5d2a9a2ac1d9012f86b475d1c4b6.tar.bz2
re PR c++/5189 (g++ -c bug.cpp crashed on simple stupid file)
PR c++/5189. * call.c (add_template_candidate_real): Do not treat member templates as copy constructors. PR c++/5189. * g++.dg/template/copy1.C: New test. From-SVN: r52260
Diffstat (limited to 'gcc')
-rw-r--r--gcc/cp/ChangeLog6
-rw-r--r--gcc/cp/call.c30
-rw-r--r--gcc/testsuite/ChangeLog6
-rw-r--r--gcc/testsuite/g++.dg/template/copy1.C14
4 files changed, 56 insertions, 0 deletions
diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog
index c075ed0..ca9251a 100644
--- a/gcc/cp/ChangeLog
+++ b/gcc/cp/ChangeLog
@@ -1,5 +1,11 @@
2002-04-12 Mark Mitchell <mark@codesourcery.com>
+ PR c++/5189.
+ * call.c (add_template_candidate_real): Do not treat member
+ templates as copy constructors.
+
+2002-04-12 Mark Mitchell <mark@codesourcery.com>
+
* decl.c (duplicate_decls): Do not copy the RTL for a variable
declaration if the old variable had an incomplete type and the new
variable does not.
diff --git a/gcc/cp/call.c b/gcc/cp/call.c
index d341fb0..12832cb 100644
--- a/gcc/cp/call.c
+++ b/gcc/cp/call.c
@@ -2221,6 +2221,36 @@ add_template_candidate_real (candidates, tmpl, ctype, explicit_targs,
if (fn == error_mark_node)
return candidates;
+ /* In [class.copy]:
+
+ A member function template is never instantiated to perform the
+ copy of a class object to an object of its class type.
+
+ It's a little unclear what this means; the standard explicitly
+ does allow a template to be used to copy a class. For example,
+ in:
+
+ struct A {
+ A(A&);
+ template <class T> A(const T&);
+ };
+ const A f ();
+ void g () { A a (f ()); }
+
+ the member template will be used to make the copy. The section
+ quoted above appears in the paragraph that forbids constructors
+ whose only parameter is (a possibly cv-qualified variant of) the
+ class type, and a logical interpretation is that the intent was
+ to forbid the instantiation of member templates which would then
+ have that form. */
+ if (DECL_CONSTRUCTOR_P (fn) && list_length (arglist) == 2)
+ {
+ tree arg_types = FUNCTION_FIRST_USER_PARMTYPE (fn);
+ if (arg_types && same_type_p (TYPE_MAIN_VARIANT (TREE_VALUE (arg_types)),
+ ctype))
+ return candidates;
+ }
+
if (obj != NULL_TREE)
/* Aha, this is a conversion function. */
cand = add_conv_candidate (candidates, fn, obj, arglist);
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index 7c9ce2c..b04b99b 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,3 +1,9 @@
+2002-04-12 Mark Mitchell <mark@codesourcery.com>
+
+ PR c++/5189.
+ * call.c (add_template_candidate_real): Do not treat member
+ templates as copy constructors.
+
2002-04-12 Richard Henderson <rth@redhat.com>
* gcc.c-torture/execute/20020406-1.c (DUPFFnew): Use calloc.
diff --git a/gcc/testsuite/g++.dg/template/copy1.C b/gcc/testsuite/g++.dg/template/copy1.C
new file mode 100644
index 0000000..3b45cc0
--- /dev/null
+++ b/gcc/testsuite/g++.dg/template/copy1.C
@@ -0,0 +1,14 @@
+// { dg-do compile }
+
+// Origin: hkluender@otg.com
+
+// PR 5189
+
+struct A
+{
+ A(A&); // { dg-error "candidate" "" }
+ template <class T> A(T);
+};
+
+A a = 0; // { dg-error "no matching function|initializing" "" }
+