public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/33235]  New: C++0x overloading problem with move constructor and trivial copy constructor
@ 2007-08-29 16:16 dgregor at gcc dot gnu dot org
  2007-08-29 16:17 ` [Bug c++/33235] " dgregor at gcc dot gnu dot org
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: dgregor at gcc dot gnu dot org @ 2007-08-29 16:16 UTC (permalink / raw)
  To: gcc-bugs

Overload resolution is picking the wrong candidate for the construction of b3,
below:

  base2 b3(static_cast<base2&&>(b));

Instead of choosing the move constructor, it is picking the trivial copy
constructor. However, adding a normal copy constructor fixes the problem.

Naturally, this only occurs in C++0x mode.


-- 
           Summary: C++0x overloading problem with move constructor and
                    trivial copy constructor
           Product: gcc
           Version: 4.3.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: dgregor at gcc dot gnu dot org


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=33235


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [Bug c++/33235] C++0x overloading problem with move constructor and trivial copy constructor
  2007-08-29 16:16 [Bug c++/33235] New: C++0x overloading problem with move constructor and trivial copy constructor dgregor at gcc dot gnu dot org
@ 2007-08-29 16:17 ` dgregor at gcc dot gnu dot org
  2007-11-05 18:42 ` dgregor at gcc dot gnu dot org
  2007-11-05 18:44 ` dgregor at gcc dot gnu dot org
  2 siblings, 0 replies; 4+ messages in thread
From: dgregor at gcc dot gnu dot org @ 2007-08-29 16:17 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #1 from dgregor at gcc dot gnu dot org  2007-08-29 16:16 -------
Created an attachment (id=14133)
 --> (http://gcc.gnu.org/bugzilla/attachment.cgi?id=14133&action=view)
Failing test-case


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=33235


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [Bug c++/33235] C++0x overloading problem with move constructor and trivial copy constructor
  2007-08-29 16:16 [Bug c++/33235] New: C++0x overloading problem with move constructor and trivial copy constructor dgregor at gcc dot gnu dot org
  2007-08-29 16:17 ` [Bug c++/33235] " dgregor at gcc dot gnu dot org
@ 2007-11-05 18:42 ` dgregor at gcc dot gnu dot org
  2007-11-05 18:44 ` dgregor at gcc dot gnu dot org
  2 siblings, 0 replies; 4+ messages in thread
From: dgregor at gcc dot gnu dot org @ 2007-11-05 18:42 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #2 from dgregor at gcc dot gnu dot org  2007-11-05 18:42 -------
Subject: Bug 33235

Author: dgregor
Date: Mon Nov  5 18:42:22 2007
New Revision: 129905

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=129905
Log:
Index: testsuite/g++.dg/cpp0x/pr33996.C
===================================================================
--- testsuite/g++.dg/cpp0x/pr33996.C    (revision 0)
+++ testsuite/g++.dg/cpp0x/pr33996.C    (revision 0)
@@ -0,0 +1,52 @@
+// { dg-options "-std=c++0x" }
+
+#define BUG
+struct type
+{
+  type() { }
+  type(const type&) { }
+
+private:
+  type(type&&);
+};
+
+template<typename _Tp>
+  struct identity
+  {
+    typedef _Tp type;
+  };
+
+template<typename _Tp>
+  inline _Tp&&
+  forward(typename identity<_Tp>::type&& __t)
+  { return __t; }
+
+struct vec
+{
+  template<typename _Args>
+    void
+    bar(_Args&& __args)
+#ifdef BUG
+    ;
+#else
+    {
+      type(forward<_Args>(__args));
+    }
+#endif
+};
+
+#ifdef BUG
+template<typename _Args>
+  void
+  vec::bar(_Args&& __args)
+  {
+    type(forward<_Args>(__args));
+  }
+#endif
+
+int main()
+{
+  vec v;
+  type c;
+  v.bar(c);
+}
Index: testsuite/g++.dg/cpp0x/rv-trivial-bug.C
===================================================================
--- testsuite/g++.dg/cpp0x/rv-trivial-bug.C     (revision 0)
+++ testsuite/g++.dg/cpp0x/rv-trivial-bug.C     (revision 0)
@@ -0,0 +1,33 @@
+// { dg-do "run" }
+// { dg-options "-std=c++0x" }
+// PR c++/33235
+#include <cassert>
+
+int move_construct = 0;
+int move_assign = 0;
+
+struct base2
+{
+    base2() {}
+    base2(base2&&) {++move_construct;}
+    base2& operator=(base2&&) {++move_assign; return *this;}
+};
+
+int test2()
+{
+    base2 b;
+    base2 b2(b);
+    assert(move_construct == 0);
+    base2 b3(static_cast<base2&&>(b));
+    assert(move_construct == 1);
+    b = b2;
+    assert(move_assign == 0);
+    b = static_cast<base2&&>(b2);
+    assert(move_assign == 1);
+}
+
+int main()
+{
+    test2();
+    return 0;
+}
Index: testsuite/g++.dg/cpp0x/pr33930.C
===================================================================
--- testsuite/g++.dg/cpp0x/pr33930.C    (revision 0)
+++ testsuite/g++.dg/cpp0x/pr33930.C    (revision 0)
@@ -0,0 +1,10 @@
+// { dg-options "-std=c++0x" }
+typedef const int* type;
+
+float& foo( const type& ggg );
+int& foo( type&& ggg );
+
+void bar( int* someptr )
+{
+  int& x = foo( someptr );
+}
Index: cp/typeck.c
===================================================================
--- cp/typeck.c (revision 129899)
+++ cp/typeck.c (working copy)
@@ -620,7 +620,7 @@ merge_types (tree t1, tree t2)
        if (code1 == POINTER_TYPE)
          t1 = build_pointer_type (target);
        else
-         t1 = build_reference_type (target);
+         t1 = cp_build_reference_type (target, TYPE_REF_IS_RVALUE (t1));
        t1 = build_type_attribute_variant (t1, attributes);
        t1 = cp_build_qualified_type (t1, quals);

Index: cp/call.c
===================================================================
--- cp/call.c   (revision 129899)
+++ cp/call.c   (working copy)
@@ -5076,7 +5076,8 @@ build_over_call (struct z_candidate *can
            return build_target_expr_with_type (arg, DECL_CONTEXT (fn));
        }
       else if (TREE_CODE (arg) == TARGET_EXPR
-              || TYPE_HAS_TRIVIAL_INIT_REF (DECL_CONTEXT (fn)))
+              || (TYPE_HAS_TRIVIAL_INIT_REF (DECL_CONTEXT (fn))
+                  && !move_fn_p (fn)))
        {
          tree to = stabilize_reference
            (build_indirect_ref (TREE_VALUE (args), 0));
@@ -6118,7 +6119,11 @@ compare_ics (conversion *ics1, conversio
   if (ics1->kind == ck_qual
       && ics2->kind == ck_qual
       && same_type_p (from_type1, from_type2))
-    return comp_cv_qual_signature (to_type1, to_type2);
+    {
+      int result = comp_cv_qual_signature (to_type1, to_type2);
+      if (result != 0)
+       return result;
+    }

   /* [over.ics.rank]


Added:
    trunk/gcc/testsuite/g++.dg/cpp0x/pr33930.C
    trunk/gcc/testsuite/g++.dg/cpp0x/pr33996.C
    trunk/gcc/testsuite/g++.dg/cpp0x/rv-trivial-bug.C
Modified:
    trunk/gcc/cp/ChangeLog
    trunk/gcc/cp/call.c
    trunk/gcc/cp/typeck.c
    trunk/gcc/testsuite/ChangeLog


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=33235


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [Bug c++/33235] C++0x overloading problem with move constructor and trivial copy constructor
  2007-08-29 16:16 [Bug c++/33235] New: C++0x overloading problem with move constructor and trivial copy constructor dgregor at gcc dot gnu dot org
  2007-08-29 16:17 ` [Bug c++/33235] " dgregor at gcc dot gnu dot org
  2007-11-05 18:42 ` dgregor at gcc dot gnu dot org
@ 2007-11-05 18:44 ` dgregor at gcc dot gnu dot org
  2 siblings, 0 replies; 4+ messages in thread
From: dgregor at gcc dot gnu dot org @ 2007-11-05 18:44 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #3 from dgregor at gcc dot gnu dot org  2007-11-05 18:44 -------
Fixed on mainline


-- 

dgregor at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
         Resolution|                            |FIXED


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=33235


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2007-11-05 18:44 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-08-29 16:16 [Bug c++/33235] New: C++0x overloading problem with move constructor and trivial copy constructor dgregor at gcc dot gnu dot org
2007-08-29 16:17 ` [Bug c++/33235] " dgregor at gcc dot gnu dot org
2007-11-05 18:42 ` dgregor at gcc dot gnu dot org
2007-11-05 18:44 ` dgregor at gcc dot gnu dot org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).