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++/65622] New: No known conversion to initializer_list with default argument in constructor


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

            Bug ID: 65622
           Summary: No known conversion to initializer_list with default
                    argument in constructor
           Product: gcc
           Version: 4.9.2
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: david.d.kretzmer at gmail dot com

------------------------------------------------
#include <initializer_list>
struct Foo
{
  Foo(std::initializer_list<int> = {}) {}
};
Foo f{1};
------------------------------------------------

The above code produces the following error (tested in 4.7, 4.8 and 4.9):

error: no matching function for call to 'Foo::Foo(<brace-enclosed initializer
list>)'
note: candidates are:
note: constexpr Foo::Foo(const Foo&)
note: no known conversion for argument 1 from 'int' to 'const Foo&'
note: constexpr Foo::Foo(Foo&&)
note: no known conversion for argument 1 from 'int' to 'Foo&&'
note: Foo::Foo(std::initializer_list<int>)
note: no known conversion for argument 1 from 'int' to
'std::initializer_list<int>'

When I remove the default argument it compiles without errors.
The error only occurs in constructors, normal functions are not affected.


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