[Bug c++/83181] New: [C++17] Invalid deduction guide accepted

redi at gcc dot gnu.org gcc-bugzilla@gcc.gnu.org
Mon Nov 27 16:43:00 GMT 2017


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

            Bug ID: 83181
           Summary: [C++17] Invalid deduction guide accepted
           Product: gcc
           Version: 7.2.1
            Status: UNCONFIRMED
          Keywords: accepts-invalid
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: redi at gcc dot gnu.org
  Target Milestone: ---

template<bool> struct enable_if { using type = void; };
template<> struct enable_if<false> { };
template<typename T> struct is_foo { static const bool value = false; };

template<typename T>
using RequireFoo = typename enable_if<is_foo<T>::value>::type;

template<typename T> struct init_list { };

template<typename T, typename A> struct X
{
  X(init_list<T>, A) { }
};

template<typename T, typename A, /* typename = */ RequireFoo<A>>
  X(init_list<T>, A) -> X<T, A>;

struct Alloc { };

template<> struct is_foo<Alloc> { static const bool value = true; };

int main()
{
  init_list<int> l;
  Alloc a;
  X x(l, a);
}

The RequireFoo<A> template parameter is invalid (it's missing "typename =") but
G++ accepts it. CLang rejects it with this error:


prog.cc:15:49: error: deduction guide template contains a template parameter
that cannot be deduced
template<typename T, typename A, RequireFoo<A>> X(init_list<T>, A) -> X<T, A>;
                                                ^
prog.cc:15:47: note: non-deducible template parameter (anonymous)
template<typename T, typename A, RequireFoo<A>> X(init_list<T>, A) -> X<T, A>;
                                              ^


More information about the Gcc-bugs mailing list