re PR c++/46831 ([C++0x] Crash when it tries to do an invalid ICS with a conversion...
authorJason Merrill <jason@redhat.com>
Mon, 21 Feb 2011 01:50:39 +0000 (20:50 -0500)
committerJason Merrill <jason@gcc.gnu.org>
Mon, 21 Feb 2011 01:50:39 +0000 (20:50 -0500)
PR c++/46831
* call.c (convert_class_to_reference): Don't try to set up a
second conv sequence for non-viable candidates.

From-SVN: r170354

gcc/cp/ChangeLog
gcc/cp/call.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/cpp0x/fntmpdefarg2.C [new file with mode: 0644]

index 848765d..4ce3f27 100644 (file)
@@ -1,5 +1,9 @@
 2011-02-20  Jason Merrill  <jason@redhat.com>
 
+       PR c++/46831
+       * call.c (convert_class_to_reference): Don't try to set up a
+       second conv sequence for non-viable candidates.
+
        PR c++/47703
        * error.c (location_of): Handle non-tagged types.
 
index 7d602b9..078542a 100644 (file)
@@ -1230,8 +1230,10 @@ convert_class_to_reference (tree reference_type, tree s, tree expr, int flags)
             rvalue of the right type is good enough.  */
          tree f = cand->fn;
          tree t2 = TREE_TYPE (TREE_TYPE (f));
-         if (TREE_CODE (t2) != REFERENCE_TYPE
-             || !reference_compatible_p (t, TREE_TYPE (t2)))
+         if (cand->viable == 0)
+           /* Don't bother looking more closely.  */;
+         else if (TREE_CODE (t2) != REFERENCE_TYPE
+                  || !reference_compatible_p (t, TREE_TYPE (t2)))
            {
              /* No need to set cand->reason here; this is most likely
                 an ambiguous match.  If it's not, either this candidate
index 91ef5f1..db45d88 100644 (file)
@@ -1,5 +1,7 @@
 2011-02-20  Jason Merrill  <jason@redhat.com>
 
+       * g++.dg/cpp0x/fntmpdefarg2.C: New.
+
        * g++.dg/overload/conv-op1.C: New.
 
        * g++.dg/cpp0x/constexpr-synth1.C: New.
diff --git a/gcc/testsuite/g++.dg/cpp0x/fntmpdefarg2.C b/gcc/testsuite/g++.dg/cpp0x/fntmpdefarg2.C
new file mode 100644 (file)
index 0000000..12cc836
--- /dev/null
@@ -0,0 +1,14 @@
+// PR c++/46831
+// { dg-options -std=c++0x }
+
+struct B { };
+struct D : B { };
+struct A {
+  template<typename T = void> operator D&();
+  operator long();
+};
+
+void f(long);
+void f(B&);
+
+int main() { f(A()); }