[Bug libstdc++/79141] New: std::pair<int,int> p = {}; fails to compile due to ambiguous overload

abdo.roig at gmail dot com gcc-bugzilla@gcc.gnu.org
Wed Jan 18 22:16:00 GMT 2017


https://gcc.gnu.org/bugzilla/show_bug.cgi?id=79141

            Bug ID: 79141
           Summary: std::pair<int,int> p = {}; fails to compile due to
                    ambiguous overload
           Product: gcc
           Version: 6.3.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: libstdc++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: abdo.roig at gmail dot com
  Target Milestone: ---

The following program did compile with gcc's standard library 6.2 but no longer
compiles on 6.3.1, reporting an error on ambiguous overload of the assignment
operator (std::pair vs initializer_list). The problem looks related to
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=77537

#include <utility>

int main() {
    std::pair<int,int> p;
    p = {};
}

It produces the following error:

$ gcc -std=c++14 gcc-bug.cpp 
gcc-bug.cpp: In function ‘int main()’:
gcc-bug.cpp:9:10: error: ambiguous overload for ‘operator=’ (operand types are
‘std::pair<int, int>’ and ‘<brace-enclosed initializer list>’)
     p = {};
          ^
In file included from /usr/include/c++/6.3.1/bits/stl_algobase.h:64:0,
                 from /usr/include/c++/6.3.1/bits/char_traits.h:39,
                 from /usr/include/c++/6.3.1/ios:40,
                 from /usr/include/c++/6.3.1/ostream:38,
                 from /usr/include/c++/6.3.1/iostream:39,
                 from gcc-bug.cpp:4:
/usr/include/c++/6.3.1/bits/stl_pair.h:359:7: note: candidate: std::pair<_T1,
_T2>& std::pair<_T1, _T2>::operator=(typename
std::conditional<std::__and_<std::is_copy_assignable<_Tp>,
std::is_copy_assignable<_T2> >::value, const std::pair<_T1, _T2>&, const
std::__nonesuch&>::type) [with _T1 = int; _T2 = int; typename
std::conditional<std::__and_<std::is_copy_assignable<_Tp>,
std::is_copy_assignable<_T2> >::value, const std::pair<_T1, _T2>&, const
std::__nonesuch&>::type = const std::pair<int, int>&]
       operator=(typename conditional<
       ^~~~~~~~
/usr/include/c++/6.3.1/bits/stl_pair.h:370:7: note: candidate: std::pair<_T1,
_T2>& std::pair<_T1, _T2>::operator=(typename
std::conditional<std::__not_<std::__and_<std::is_copy_assignable<_Tp>,
std::is_copy_assignable<_T2> > >::value, const std::pair<_T1, _T2>&, const
std::__nonesuch&>::type) [with _T1 = int; _T2 = int; typename
std::conditional<std::__not_<std::__and_<std::is_copy_assignable<_Tp>,
std::is_copy_assignable<_T2> > >::value, const std::pair<_T1, _T2>&, const
std::__nonesuch&>::type = const std::__nonesuch&] <deleted>
       operator=(typename conditional<
       ^~~~~~~~
/usr/include/c++/6.3.1/bits/stl_pair.h:376:7: note: candidate: std::pair<_T1,
_T2>& std::pair<_T1, _T2>::operator=(typename
std::conditional<std::__and_<std::is_move_assignable<_Tp>,
std::is_move_assignable<_T2> >::value, std::pair<_T1, _T2>&&,
std::__nonesuch&&>::type) [with _T1 = int; _T2 = int; typename
std::conditional<std::__and_<std::is_move_assignable<_Tp>,
std::is_move_assignable<_T2> >::value, std::pair<_T1, _T2>&&,
std::__nonesuch&&>::type = std::pair<int, int>&&]
       operator=(typename conditional<
       ^~~~~~~~


More information about the Gcc-bugs mailing list