public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug libstdc++/43917]  New: [C++0x] std::swap not working
@ 2010-04-28  4:39 navin dot kumar at gmail dot com
  2010-04-28  9:07 ` [Bug libstdc++/43917] " rguenth at gcc dot gnu dot org
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: navin dot kumar at gmail dot com @ 2010-04-28  4:39 UTC (permalink / raw)
  To: gcc-bugs

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain, Size: 1451 bytes --]

Simple programs like the following do not compile under -std=c++0x on GCC 4.5.0
- due to the new GCC enforcement of C++0x rules regarding l-values not being
allowed to bind to "&&".

#include <iostream>
#include <math.h>

int main(int argc, char** argv)
{
    std::pair< std::string, std::string > x("hello", "world");
    std::pair< std::string, std::string > y("test", "123");
    std::swap(x, y);
    std::cout << x.first << ' ' << x.second << std::endl;
    return 0;
}

Compiler output:
In function ‘void std::swap(std::pair<_T1, _T2>&, std::pair<_T1, _T2>&) [with
_T1 = std::basic_string<char>, _T2 = std::basic_string<char>]’:
error: cannot bind ‘std::pair<std::basic_string<char>, std::basic_string<char>
>’ lvalue to ‘std::pair<std::basic_string<char>, std::basic_string<char> >&&’
error:   initializing argument 1 of ‘void std::pair<_T1,
_T2>::swap(std::pair<_T1, _T2>&&) [with _T1 = std::basic_string<char>, _T2 =
std::basic_string<char>, std::pair<_T1, _T2> =
std::pair<std::basic_string<char>, std::basic_string<char> >]’

Likely related to bug# 43785


-- 
           Summary: [C++0x] std::swap not working
           Product: gcc
           Version: 4.5.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: libstdc++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: navin dot kumar at gmail dot com


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


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

* [Bug libstdc++/43917] [C++0x] std::swap not working
  2010-04-28  4:39 [Bug libstdc++/43917] New: [C++0x] std::swap not working navin dot kumar at gmail dot com
@ 2010-04-28  9:07 ` rguenth at gcc dot gnu dot org
  2010-04-28  9:10 ` paolo dot carlini at oracle dot com
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: rguenth at gcc dot gnu dot org @ 2010-04-28  9:07 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #1 from rguenth at gcc dot gnu dot org  2010-04-28 09:07 -------
*** Bug 43916 has been marked as a duplicate of this bug. ***


-- 


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


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

* [Bug libstdc++/43917] [C++0x] std::swap not working
  2010-04-28  4:39 [Bug libstdc++/43917] New: [C++0x] std::swap not working navin dot kumar at gmail dot com
  2010-04-28  9:07 ` [Bug libstdc++/43917] " rguenth at gcc dot gnu dot org
@ 2010-04-28  9:10 ` paolo dot carlini at oracle dot com
  2010-04-28 17:43 ` navin dot kumar at gmail dot com
  2010-04-28 18:41 ` redi at gcc dot gnu dot org
  3 siblings, 0 replies; 5+ messages in thread
From: paolo dot carlini at oracle dot com @ 2010-04-28  9:10 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #2 from paolo dot carlini at oracle dot com  2010-04-28 09:09 -------
Likely, something is broken in your installation, this problem cannot be
reproduced in a sane installation of 4.5.0 or mainline. Note that the std::swap
overload for std::pair takes *lvalue* references.


-- 

paolo dot carlini at oracle dot com changed:

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


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


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

* [Bug libstdc++/43917] [C++0x] std::swap not working
  2010-04-28  4:39 [Bug libstdc++/43917] New: [C++0x] std::swap not working navin dot kumar at gmail dot com
  2010-04-28  9:07 ` [Bug libstdc++/43917] " rguenth at gcc dot gnu dot org
  2010-04-28  9:10 ` paolo dot carlini at oracle dot com
@ 2010-04-28 17:43 ` navin dot kumar at gmail dot com
  2010-04-28 18:41 ` redi at gcc dot gnu dot org
  3 siblings, 0 replies; 5+ messages in thread
From: navin dot kumar at gmail dot com @ 2010-04-28 17:43 UTC (permalink / raw)
  To: gcc-bugs

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain, Size: 1664 bytes --]



------- Comment #3 from navin dot kumar at gmail dot com  2010-04-28 17:43 -------
Are you compiling with -std=c++0x or without?  It compiles fine without the
-std=c++0x flag.  The issue is when it is supplied.

Look at line 134 of include/c++/4.5.0/bits/stl_pair.h; inside a #ifdef
__GXX_EXPERIMENTAL_CXX0X__ tag there is the following function:

      void
      swap(pair&& __p)
      {
    using std::swap;
    swap(first, __p.first);
    swap(second, __p.second);   
      }

The compiler error stems from trying to pass a pair l-value reference to
pair&&.

Here's the compiler error with line numbers:
include/c++/4.5.0/bits/stl_pair.h: In function ‘void std::swap(std::pair<_T1,
_T2>&, std::pair<_T1, _T2>&) [with _T1 = std::basic_string<char>, _T2 =
std::basic_string<char>]’:
test.cpp:8:19:   instantiated from here
include/c++/4.5.0/bits/stl_pair.h:187:7: error: cannot bind
‘std::pair<std::basic_string<char>, std::basic_string<char> >’ lvalue to
‘std::pair<std::basic_string<char>, std::basic_string<char> >&&’
include/c++/4.5.0/bits/stl_pair.h:134:7: error:   initializing argument 1 of
‘void std::pair<_T1, _T2>::swap(std::pair<_T1, _T2>&&) [with _T1 =
std::basic_string<char>, _T2 = std::basic_string<char>, std::pair<_T1, _T2> =
std::pair<std::basic_string<char>, std::basic_string<char> >]’


-- 

navin dot kumar at gmail dot com changed:

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


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


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

* [Bug libstdc++/43917] [C++0x] std::swap not working
  2010-04-28  4:39 [Bug libstdc++/43917] New: [C++0x] std::swap not working navin dot kumar at gmail dot com
                   ` (2 preceding siblings ...)
  2010-04-28 17:43 ` navin dot kumar at gmail dot com
@ 2010-04-28 18:41 ` redi at gcc dot gnu dot org
  3 siblings, 0 replies; 5+ messages in thread
From: redi at gcc dot gnu dot org @ 2010-04-28 18:41 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #4 from redi at gcc dot gnu dot org  2010-04-28 18:40 -------
No, that's not what pair::swap looks like in 4.5.0, your installation is
broken. This is what I have in 4.5.0

      void
      swap(pair& __p)
      {
        using std::swap;
        swap(first, __p.first);
        swap(second, __p.second);
      }

Somehow you have a header from 4.4 in your 4.5 tree, or you have been manually
messing with headers


-- 

redi at gcc dot gnu dot org changed:

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


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


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

end of thread, other threads:[~2010-04-28 18:41 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-04-28  4:39 [Bug libstdc++/43917] New: [C++0x] std::swap not working navin dot kumar at gmail dot com
2010-04-28  9:07 ` [Bug libstdc++/43917] " rguenth at gcc dot gnu dot org
2010-04-28  9:10 ` paolo dot carlini at oracle dot com
2010-04-28 17:43 ` navin dot kumar at gmail dot com
2010-04-28 18:41 ` redi 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).