On Mon, 12 Apr 2021, Jason Merrill wrote:

> On 4/10/21 3:57 PM, Patrick Palka wrote:
> > Here, in C++17 mode, we only pedwarn about the use of alias CTAD and
> > then later ICE from alias_ctad_tweaks when attempting to add a
> > constraint to one of the guides.  Since the construction of the guides
> > of an alias template effectively relies on concepts, we shouldn't be
> > permissive about alias CTAD in C++17 mode, so this patch turns the
> > pertinent pedwarn in do_class_deduction into an error.
> 
> Sounds good.
> 
> > In order to get a consistent diagnostic for B() vs the other forms in
> > the added testcase, I had to remove the special handling of CTAD with
> > empty initializer in build_functional_cast_1 so that we always pass
> > 'complain' to do_auto_deduction.
> 
> Did you compare the resulting diagnostics when deduction fails other than for
> trying to do alias deduction in C++17 mode?

For plain CTAD, e.g. for

  template <class T> struct A { };
  auto a = A();

we previously emitted

test.C:2:10: error: cannot deduce template arguments for ‘A<...auto...>’ from 
‘()’
    2 | auto a = A();
      |          ^~~

and now we emit

test.C:2:12: error: class template argument deduction failed:
    2 | auto a = A();
      |            ^
test.C:2:12: error: no matching function for call to ‘A()’
test.C:1:27: note: candidate: ‘template<class T> A()-> A<T>’
    1 | template <class T> struct A { };
      |                           ^
test.C:1:27: note:   template argument deduction/substitution failed:
test.C:2:12: note:   couldn’t deduce template parameter ‘T’
    2 | auto a = A();
      |            ^
test.C:1:27: note: candidate: ‘template<class T> A(A<T>)-> A<T>’
    1 | template <class T> struct A { };
      |                           ^
test.C:1:27: note:   template argument deduction/substitution failed:
test.C:2:12: note:   candidate expects 1 argument, 0 provided
    2 | auto a = A();
      |            ^

which is consistent with what we already emit for failed CTAD of the
form A{}, A(args) and A{args}.

I think this change should have no diagnostic/functional impact in other
deduction situations because the code path is guarded by a
CLASS_PLACEHOLDER_TEMPLATE check (and we create template placeholders
only in C++17 mode).

Reply via email to