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++/80987] New: Existence of a std::initializer_list constructor breaks deduction guides


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

            Bug ID: 80987
           Summary: Existence of a std::initializer_list constructor
                    breaks deduction guides
           Product: gcc
           Version: 8.0
            Status: UNCONFIRMED
          Keywords: rejects-valid
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: redi at gcc dot gnu.org
  Target Milestone: ---

This valid C++17 program is rejected:

namespace std
{
    using size_t = decltype(sizeof(0));

    template<typename T> struct initializer_list {
        constexpr initializer_list(const T*, size_t) { }
        T* _M_array;
        size_t _M_len;
    };

    template<typename C, typename A> struct basic_string {
        template<typename Iter> basic_string(Iter, const A& = A()) { }
        basic_string(std::initializer_list<C>) { }
    };

    template<typename T> struct allocator { };

    template<typename CharT, typename Allocator = allocator<CharT>>
        basic_string(CharT, Allocator = Allocator())
            -> basic_string<CharT, Allocator>;
}

int main()
{
    const char* it = "";
    std::allocator<char> a;
    std::basic_string s1(it, a);  // OK
    std::basic_string s2(it);     // OK
    std::basic_string s3{it, a};  // ERROR
}

prog.cc: In function 'int main()':
prog.cc:29:31: error: class template argument deduction failed:
     std::basic_string s3{it, a};
                               ^
prog.cc:29:31: error: no matching function for call to
'basic_string(<brace-enclosed initializer list>)'
prog.cc:19:9: note: candidate: 'template<class CharT, class Allocator>
std::basic_string(CharT, Allocator)-> std::basic_string<CharT, Allocator>'
         basic_string(CharT, Allocator = Allocator())
         ^~~~~~~~~~~~
prog.cc:19:9: note:   template argument deduction/substitution failed:
prog.cc:29:31: note:   couldn't deduce template parameter 'CharT'
     std::basic_string s3{it, a};
                               ^
prog.cc:13:9: note: candidate: 'template<class C, class A>
basic_string(std::initializer_list<C>)-> std::basic_string<C, A>'
         basic_string(std::initializer_list<C>) { }
         ^~~~~~~~~~~~
prog.cc:13:9: note:   template argument deduction/substitution failed:
prog.cc:29:31: note:   deduced conflicting types for parameter 'C' ('const
char*' and 'std::allocator<char>')
     std::basic_string s3{it, a};
                               ^
prog.cc:12:33: note: candidate: 'template<class C, class A, class Iter>
basic_string(Iter, const A&)-> std::basic_string<C, A>'
         template<typename Iter> basic_string(Iter, const A& = A()) { }
                                 ^~~~~~~~~~~~
prog.cc:12:33: note:   template argument deduction/substitution failed:
prog.cc:29:31: note:   couldn't deduce template parameter 'C'
     std::basic_string s3{it, a};
                               ^
prog.cc:11:45: note: candidate: 'template<class C, class A>
basic_string(std::basic_string<C, A>)-> std::basic_string<C, A>'
     template<typename C, typename A> struct basic_string {
                                             ^~~~~~~~~~~~
prog.cc:11:45: note:   template argument deduction/substitution failed:
prog.cc:29:31: note:   couldn't deduce template parameter 'C'
     std::basic_string s3{it, a};
                               ^

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