public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug libstdc++/57049] New: std::swap does self move assignment, which is illegal
@ 2013-04-23 15:46 tudorb at fb dot com
  2013-04-23 15:54 ` [Bug libstdc++/57049] " tudorb at fb dot com
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: tudorb at fb dot com @ 2013-04-23 15:46 UTC (permalink / raw)
  To: gcc-bugs


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

             Bug #: 57049
           Summary: std::swap does self move assignment, which is illegal
    Classification: Unclassified
           Product: gcc
           Version: 4.7.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: libstdc++
        AssignedTo: unassigned@gcc.gnu.org
        ReportedBy: tudorb@fb.com


Created attachment 29922
  --> http://gcc.gnu.org/bugzilla/attachment.cgi?id=29922
sample program that illustrates incorrect behavior

The default implementation of std::swap does self-move-assignment when calling
swap(a, a), which is illegal according to 17.6.4.9.


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

* [Bug libstdc++/57049] std::swap does self move assignment, which is illegal
  2013-04-23 15:46 [Bug libstdc++/57049] New: std::swap does self move assignment, which is illegal tudorb at fb dot com
@ 2013-04-23 15:54 ` tudorb at fb dot com
  2013-04-25  9:55 ` daniel.kruegler at googlemail dot com
  2013-06-11  9:00 ` paolo.carlini at oracle dot com
  2 siblings, 0 replies; 4+ messages in thread
From: tudorb at fb dot com @ 2013-04-23 15:54 UTC (permalink / raw)
  To: gcc-bugs


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

--- Comment #1 from Tudor Bosman <tudorb at fb dot com> 2013-04-23 15:54:18 UTC ---
Actually, I'll take this back.  I don't believe this is a bug.

17.6.4.9 constraints arguments passed to STL functions.  So if there is a
library function that takes a rvalue argument (such as
string::operator=(string&& other)), then the library is free to assume that the
argument doesn't alias (so &other != this).  So the assertion in basic_fbstring
is correct.

The default implementation of swap() does self-move assignment.  That would be
illegal if the types were MoveAssignable STL types (because then they'd call
T::operator=(T&&) which would be illegal according to 17.6.4.9) BUT ALL STL
TYPES HAVE SPECIALIZED IMPLEMENTATIONS OF SWAP which don't do self move
assignment.

So the default swap() will do self-move-assignment on user types, but there's
no language in the standard that bans self-move-assignment there.


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

* [Bug libstdc++/57049] std::swap does self move assignment, which is illegal
  2013-04-23 15:46 [Bug libstdc++/57049] New: std::swap does self move assignment, which is illegal tudorb at fb dot com
  2013-04-23 15:54 ` [Bug libstdc++/57049] " tudorb at fb dot com
@ 2013-04-25  9:55 ` daniel.kruegler at googlemail dot com
  2013-06-11  9:00 ` paolo.carlini at oracle dot com
  2 siblings, 0 replies; 4+ messages in thread
From: daniel.kruegler at googlemail dot com @ 2013-04-25  9:55 UTC (permalink / raw)
  To: gcc-bugs


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

Daniel Krügler <daniel.kruegler at googlemail dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |daniel.kruegler at
                   |                            |googlemail dot com

--- Comment #2 from Daniel Krügler <daniel.kruegler at googlemail dot com> 2013-04-25 09:55:47 UTC ---
Here are two different things to consider:

1) The standard library specification of basic_string's move-assignment
operator currently requires that it works for self-assignment:

<quote>
21 Effects: If *this and str are not the same object, modifies *this as shown
in Table 71. [...]

22 If *this and str are the same object, the member has no effect.
</quote>

This might or might not change, depending on the outcome of LWG issue

http://cplusplus.github.io/LWG/lwg-active.html#2063

2) The generic swap template from <utility> imposes requirements on the
argument types and describes what it does (which can only rely on the
requirements). So if you call swap with the same argument value and if for
these argument values the move-assignment is undefined behaviour, you get what
you are asking for. There is no single evidence that swap would be even allowed
to prevent swapping for identical arguments, because the semantics are
specified clearly to exchange the two values.
>From gcc-bugs-return-420941-listarch-gcc-bugs=gcc.gnu.org@gcc.gnu.org Thu Apr 25 10:01:43 2013
Return-Path: <gcc-bugs-return-420941-listarch-gcc-bugs=gcc.gnu.org@gcc.gnu.org>
Delivered-To: listarch-gcc-bugs@gcc.gnu.org
Received: (qmail 27091 invoked by alias); 25 Apr 2013 10:01:43 -0000
Mailing-List: contact gcc-bugs-help@gcc.gnu.org; run by ezmlm
Precedence: bulk
List-Id: <gcc-bugs.gcc.gnu.org>
List-Archive: <http://gcc.gnu.org/ml/gcc-bugs/>
List-Post: <mailto:gcc-bugs@gcc.gnu.org>
List-Help: <mailto:gcc-bugs-help@gcc.gnu.org>
Sender: gcc-bugs-owner@gcc.gnu.org
Delivered-To: mailing list gcc-bugs@gcc.gnu.org
Received: (qmail 27059 invoked by uid 48); 25 Apr 2013 10:01:40 -0000
From: "redi at gcc dot gnu.org" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug libstdc++/57065] incorrect default allocator template for debug and profile unordered_map
Date: Thu, 25 Apr 2013 10:01:00 -0000
X-Bugzilla-Reason: CC
X-Bugzilla-Type: changed
X-Bugzilla-Watch-Reason: None
X-Bugzilla-Product: gcc
X-Bugzilla-Component: libstdc++
X-Bugzilla-Keywords:
X-Bugzilla-Severity: minor
X-Bugzilla-Who: redi at gcc dot gnu.org
X-Bugzilla-Status: RESOLVED
X-Bugzilla-Priority: P3
X-Bugzilla-Assigned-To: paolo.carlini at oracle dot com
X-Bugzilla-Target-Milestone: 4.9.0
X-Bugzilla-Changed-Fields:
Message-ID: <bug-57065-4-fcv4AfXqnE@http.gcc.gnu.org/bugzilla/>
In-Reply-To: <bug-57065-4@http.gcc.gnu.org/bugzilla/>
References: <bug-57065-4@http.gcc.gnu.org/bugzilla/>
X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/
Auto-Submitted: auto-generated
Content-Type: text/plain; charset="UTF-8"
MIME-Version: 1.0
X-SW-Source: 2013-04/txt/msg02086.txt.bz2
Content-length: 173


http://gcc.gnu.org/bugzilla/show_bug.cgi?idW065

--- Comment #3 from Jonathan Wakely <redi at gcc dot gnu.org> 2013-04-25 10:01:40 UTC ---
Good catch, thanks, Kenny


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

* [Bug libstdc++/57049] std::swap does self move assignment, which is illegal
  2013-04-23 15:46 [Bug libstdc++/57049] New: std::swap does self move assignment, which is illegal tudorb at fb dot com
  2013-04-23 15:54 ` [Bug libstdc++/57049] " tudorb at fb dot com
  2013-04-25  9:55 ` daniel.kruegler at googlemail dot com
@ 2013-06-11  9:00 ` paolo.carlini at oracle dot com
  2 siblings, 0 replies; 4+ messages in thread
From: paolo.carlini at oracle dot com @ 2013-06-11  9:00 UTC (permalink / raw)
  To: gcc-bugs

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

Paolo Carlini <paolo.carlini at oracle dot com> changed:

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

--- Comment #3 from Paolo Carlini <paolo.carlini at oracle dot com> ---
Closing then.


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

end of thread, other threads:[~2013-06-11  9:00 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-04-23 15:46 [Bug libstdc++/57049] New: std::swap does self move assignment, which is illegal tudorb at fb dot com
2013-04-23 15:54 ` [Bug libstdc++/57049] " tudorb at fb dot com
2013-04-25  9:55 ` daniel.kruegler at googlemail dot com
2013-06-11  9:00 ` paolo.carlini at oracle dot com

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).