[PATCH] D56731: Add -Wimplicit-ctad warning to diagnose CTAD on types with no user defined deduction guides.

Eric Fiselier via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Tue Jan 15 11:13:12 PST 2019


EricWF marked 6 inline comments as done.
EricWF added inline comments.


================
Comment at: include/clang/Basic/DiagnosticSemaKinds.td:2129
+def warn_class_template_argument_deduction_no_user_defined_guides : Warning<
+  "class template argument deduction for %0 that has no user defined deduction guides" >,
+  InGroup<ImplicitCTADUsage>, DefaultIgnore;
----------------
lebedev.ri wrote:
> Quuxplusone wrote:
> > `s/user defined/user-defined/`, and perhaps `s/that has/with/` for brevity.
> `class template argument deduction <was used? happened?> for %0 that has no user`
> the sentence looks incomplete to me.
How about `using class template argument deduction for %0 that has no user-defined deduction guides`?


================
Comment at: test/SemaCXX/cxx1z-class-template-argument-deduction.cpp:426
+// expected-warning at +1 {{class template argument deduction for 'NoExplicit' that has no user defined deduction guides}}
+NoExplicit ne(42);
+
----------------
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.



Repository:
  rC Clang

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

https://reviews.llvm.org/D56731





More information about the cfe-commits mailing list