[PATCH] PR c++/46824

Dodji Seketeli dodji@redhat.com
Fri Mar 11 16:49:00 GMT 2011


Hello,

In my fix for PR c++/42260 I wanted to exclude conversion operators
that return dependent types from the candidates functions during
overload resolution in cases like:

    struct A
    {
	  template<typename T> operator T*();
    };

    int i = *A();

During the overload resolution to determine the conversions that would
convert A into a non-class type, we don't want the conversion function
template to be part of the candidates.

I requested the target type of the conversion to be complete and that
was too strong and is not causing the code in the example of the patch
below to be rejected.

I believe Just requesting it to be non-dependent should be enough.

Meanwhile, this comment in the code:

    For every cv-qualified or cv-unqualified complete object type T,
    there exist candidate operator functions of the form

		 T&      operator*(T*);

is not correct (anymore?).  In [over.built]/6 it reads:

    For every cv-qualified or cv-unqualified object type T, there exist
    candidate operator functions of the form

	T&     operator*(T *);

Apparently in 1996 the type was required to be complete in the code
and the comment but that changed since then.

So I removed the "complete" from the comment.  I wish I had double
checked that in the spec earlier :-(

Here is the patch I am currently testing against trunk.

-- 
		Dodji

>From 9d9f38e1ef36a6ae1240f72834ed6657e382dc0e Mon Sep 17 00:00:00 2001
From: Dodji Seketeli <dodji@redhat.com>
Date: Fri, 11 Mar 2011 17:13:16 +0100
Subject: [PATCH] PR c++/46824

gcc/cp/

	* call.c (add_builtin_candidate)<case INDIRECT_REF>: The type
	of the argument of the indirection operator should not be
	dependent.  Fix the comment.

gcc/testsuite/

	* g++.dg/conversion/cast3.C: New test.
---
 gcc/cp/call.c                           |    4 ++--
 gcc/testsuite/g++.dg/conversion/cast3.C |   14 ++++++++++++++
 2 files changed, 16 insertions(+), 2 deletions(-)
 create mode 100644 gcc/testsuite/g++.dg/conversion/cast3.C

diff --git a/gcc/cp/call.c b/gcc/cp/call.c
index a297f53..5953e35 100644
--- a/gcc/cp/call.c
+++ b/gcc/cp/call.c
@@ -2150,7 +2150,7 @@ add_builtin_candidate (struct z_candidate **candidates, enum tree_code code,
 	}
       return;
 
-/* 7 For every cv-qualified or cv-unqualified complete object type T, there
+/* 7 For every cv-qualified or cv-unqualified object type T, there
      exist candidate operator functions of the form
 
 	     T&      operator*(T*);
@@ -2161,7 +2161,7 @@ add_builtin_candidate (struct z_candidate **candidates, enum tree_code code,
 
     case INDIRECT_REF:
       if (TREE_CODE (type1) == POINTER_TYPE
-	  && is_complete (TREE_TYPE (type1))
+	  && !uses_template_parms (TREE_TYPE (type1))
 	  && (TYPE_PTROB_P (type1)
 	      || TREE_CODE (TREE_TYPE (type1)) == FUNCTION_TYPE))
 	break;
diff --git a/gcc/testsuite/g++.dg/conversion/cast3.C b/gcc/testsuite/g++.dg/conversion/cast3.C
new file mode 100644
index 0000000..43287a1
--- /dev/null
+++ b/gcc/testsuite/g++.dg/conversion/cast3.C
@@ -0,0 +1,14 @@
+// Origin: PR c++/46824
+
+class Incomplete;
+struct Ptr
+{
+  operator Incomplete*();
+};
+
+int
+main()
+{
+  Ptr p;
+  *p;
+}
-- 
1.7.3.4



More information about the Gcc-patches mailing list