diff mbox

PR c++/46824

Message ID m3pqpx38lt.fsf@redhat.com
State New
Headers show

Commit Message

Dodji Seketeli March 11, 2011, 4:49 p.m. UTC
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.

Comments

Jason Merrill March 11, 2011, 5:08 p.m. UTC | #1
OK.

Jason
diff mbox

Patch

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;
+}