N3323
authorJason Merrill <jason@redhat.com>
Mon, 22 Apr 2013 19:25:23 +0000 (15:25 -0400)
committerJason Merrill <jason@gcc.gnu.org>
Mon, 22 Apr 2013 19:25:23 +0000 (15:25 -0400)
* cvt.c (build_expr_type_conversion): Two conversions that return
the same type aren't necessarily ambiguous.

From-SVN: r198157

gcc/cp/ChangeLog
gcc/cp/cvt.c
gcc/testsuite/g++.dg/cpp1y/context-conv1.C [new file with mode: 0644]

index 34f207f364b0801be77c0309a86a0a2b678db9f4..57c2fc3f5713eed7c8dbb33fbd28d19f8b4ec116 100644 (file)
@@ -1,5 +1,9 @@
 2013-04-22  Jason Merrill  <jason@redhat.com>
 
+       N3323
+       * cvt.c (build_expr_type_conversion): Two conversions that return
+       the same type aren't necessarily ambiguous.
+
        N3648
        * parser.c (cp_parser_lambda_introducer): Make lambda capture init
        pedwarn unconditional except in C++1y mode.
index a3b73580b234bce1304e9e37e59939b735afa3a4..93be76a6c05a67af98ffa1f2ec6056b586015e3e 100644 (file)
@@ -1630,17 +1630,24 @@ build_expr_type_conversion (int desires, tree expr, bool complain)
        {
          if (winner)
            {
-             if (complain)
+             tree winner_type
+               = non_reference (TREE_TYPE (TREE_TYPE (winner)));
+
+             if (!same_type_ignoring_top_level_qualifiers_p (winner_type,
+                                                             candidate))
                {
-                 error ("ambiguous default type conversion from %qT",
-                        basetype);
-                 error ("  candidate conversions include %qD and %qD",
-                        winner, cand);
+                 if (complain)
+                   {
+                     error ("ambiguous default type conversion from %qT",
+                            basetype);
+                     error ("  candidate conversions include %qD and %qD",
+                            winner, cand);
+                   }
+                 return error_mark_node;
                }
-             return error_mark_node;
            }
-         else
-           winner = cand;
+
+         winner = cand;
        }
     }
 
diff --git a/gcc/testsuite/g++.dg/cpp1y/context-conv1.C b/gcc/testsuite/g++.dg/cpp1y/context-conv1.C
new file mode 100644 (file)
index 0000000..fe20cab
--- /dev/null
@@ -0,0 +1,32 @@
+// N3323
+
+#define assert(E) if(!(E))__builtin_abort();
+
+template<class T>
+class zero_init
+{
+public:
+  zero_init( )
+    : val( static_cast<T>(0) ) { }
+  zero_init( T val ) : val( val )
+  { }
+  operator T & ( ) { return val; }
+  operator T ( ) const { return val; }
+private:
+  T val;
+};
+
+void f()
+{
+  zero_init<int*> p; assert( p == 0 );
+  p = new int(7);
+  assert( *p == 7 );
+  delete p; // error!
+
+  zero_init<int> i; assert( i == 0 );
+  i = 7;
+  assert( i == 7 );
+  switch( i ) {  } // error!
+
+  int *vp = new int[i];
+}