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 848765d2f92b7229463e1b97f0a5c30b9c889061..4ce3f27be7cf2f949a1ab4ea7b25a1e64fdd1599 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 7d602b94d22c1bbb6e2ebe85d8120b5567a7e6cc..078542aae976fe5f65f8600b87770f8e49b4aa6a 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 91ef5f18d8ca1574b7a46eff425e3d86965c3377..db45d88aaef002a3c9504100d7004cce739f83f9 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()); }