This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug c++/44487] New: pair of references doesn't work in c++0x mode


This program doesn't compile with g++-4.5 -std=c++0x -c test.cpp

I'm using:
g++-4.5 (Debian 4.5.0-5) 4.5.1 20100602 (prerelease)

I also verified the same behavior on:
 g++ (Debian 20100530-1) 4.6.0 20100530 (experimental) [trunk revision 160047]

#include <utility>

int x, y;
std::pair<int &,int &> foo() {
    std::pair<int &, int &> blah(x, y);
    return blah;
}

It says:
In file included from /usr/include/c++/4.5/utility:71:0,
                 from /tmp/test.cpp:1:
/usr/include/c++/4.5/bits/stl_pair.h: In constructor ?std::pair<_T1,
_T2>::pair(std::pair<_T1, _T2>&&) [with _T1 = int&, _T2 = int&, std::pair<_T1,
_T2> = std::pair<int&, int&>]?:
/tmp/test.cpp:8:12:   instantiated from here
/usr/include/c++/4.5/bits/stl_pair.h:113:30: error: invalid initialization of
non-const reference of type ?int&? from an rvalue of type
?std::remove_reference<int&>::type?
/usr/include/c++/4.5/bits/stl_pair.h:113:30: error: invalid initialization of
non-const reference of type ?int&? from an rvalue of type
?std::remove_reference<int&>::type?


It works without -std=c++0x, and it seems like that ought to work in c++0x too.

Furthermore, this slightly modified program, making "blah" const (which I think
shouldn't make a difference, as it's the outermost qualifier of a local
variable) causes it to successfully compile:

#include <utility>

int x, y;
std::pair<int &,int &> foo() {
    const std::pair<int &, int &> blah(x, y);
    return blah;
}


-- 
           Summary: pair of references doesn't work in c++0x mode
           Product: gcc
           Version: 4.5.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: foom at fuhm dot net


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]