This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c++/80736] New: Wrong overload picked with uniform initialization
- From: "d.frey at gmx dot de" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Sat, 13 May 2017 09:21:38 +0000
- Subject: [Bug c++/80736] New: Wrong overload picked with uniform initialization
- Auto-submitted: auto-generated
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=80736
Bug ID: 80736
Summary: Wrong overload picked with uniform initialization
Product: gcc
Version: unknown
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: d.frey at gmx dot de
Target Milestone: ---
The following program leads to an infinite recursion:
#include <initializer_list>
template< typename T >
struct vector
{
vector() = default;
vector( const vector& ) = default; // 1
vector( std::initializer_list< T > ) {} // 2
};
template< typename T >
struct model
{
T data;
model( const T& v )
// : data( v ) // chooses 1
: data{ v } // chooses 2 over 1, creating an infinite recursion
{
}
};
struct drawable
{
template< typename T >
drawable( const T& v )
{
model< T >{ v };
}
};
int main()
{
vector< drawable > v;
drawable d = v;
(void)d;
}
The problem is that the ctor with the initializer_list is preferred over the
copy-ctor. This should be fixed by DR 1467 (AFAICT), but GCC still gets it
wrong in the above program.
Tested with GCC 4.9.3, 5.4, 6.3, and 7.1.
Clang 3.7+ gets it right, previous versions of Clang have the same problem as
GCC.
Link: https://wandbox.org/permlink/MiS6pzVbGOO8Hxaw