Quuxplusone added inline comments.

================
Comment at: test/SemaCXX/cxx1z-class-template-argument-deduction.cpp:426
+// expected-warning@+1 {{class template argument deduction for 'NoExplicit' 
that has no user defined deduction guides}}
+NoExplicit ne(42);
+
----------------
EricWF wrote:
> Quuxplusone wrote:
> > I suggest that additional (more realistic) motivating examples can be found 
> > in STL's CppCon 2018 talk. E.g.
> > 
> > ```
> > template<class T, class U>
> > struct Pair {
> >     T first; U second;
> >     explicit Pair(const T& t, const U& u) : first(t), second(u) {}
> > };
> > Pair p(42, "hello world");  // constructs a Pair<int, char[12]>
> > 
> > template<class T, class U>
> > struct Pair2 {
> >     T first; U second;
> >     explicit Pair2(T t, U u) : first(t), second(u) {}
> > };
> > Pair2 p(42, "hello world");  // constructs a Pair2<int, const char*>
> > ```
> > 
> > I would expect (and, with your patch, receive) diagnostics for both of 
> > these.
> > 
> > But for something like `Vector("a", "b")` your patch gives no diagnostic: 
> > https://godbolt.org/z/_9zhav
> > And for something like [`std::optional o(x);` in generic 
> > context](https://quuxplusone.github.io/blog/2018/12/11/dont-inherit-from-std-types/)
> >  your patch gives no diagnostic.
> > 
> > I do have a patch out for a general-purpose `-Wctad` that would give 
> > warnings on those latter cases as well: D54565
> > I think `-Wimplicit-ctad` is a good start, but it doesn't solve all the 
> > cases I'd like to see solved.
> I'll add the tests you described. And indeed, this solution is incomplete.
> 
> Can you expand on you `std::optional` example? I don't understand it.
> 
> Can you expand on you std::optional example? I don't understand it.

https://quuxplusone.github.io/blog/2018/12/09/wctad/
https://akrzemi1.wordpress.com/2018/12/09/deducing-your-intentions/

Essentially, CTAD tries to guess your intention, and it's easy for CTAD to 
guess wrong //in a generic context//.  The `vector v("a", "b")` example is 
about being in a concrete context and always guessing wrong; the more 
pernicious `auto o = optional(x)` example is about being in a generic context 
and //sometimes// guessing right and sometimes guessing wrong, depending on the 
type of `x` (and maybe not finding out until after you've shipped your 
header-only library).


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D56731/new/

https://reviews.llvm.org/D56731



_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to