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

Richard Smith - zygoloid via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Tue Jan 15 17:45:33 PST 2019


rsmith added a comment.

[This discussion should probably move to cfe-dev@, since it's not directly relevant for this patch.]

In D56731#1358907 <https://reviews.llvm.org/D56731#1358907>, @Quuxplusone wrote:

> > Concretely, I think we could warn if, during template instantiation from a type-dependent initializer, we select the copy deduction candidate and there was another viable candidate (the `optional o(x)` case, the `tuple t{args...}` case, etc), maybe under a new `-Wctad-unwrap` or similar.
>
> The trick is that you have to give the warning //even when the copy deduction candidate is not selected// — e.g. `tuple t{args...}` when `args...` is not a 1-parameter pack //right now// but if it might turn out to be a 1-parameter pack at "production time" (after the library has reached the customer).


There's a balance here between practical usability and warning as early as possible. If the template is never actually instantiated with only one argument, then warning on it is noise, and noise that'd be hard to turn off without losing the value of the warning. So we need to decide whether we want a (hopefully!) low-false-positive warning that helps library vendors that think to test this corner case themselves, or a (presumably) higher-false-positive warning that also helps the incautious library vendors that insufficiently tested their library, and we need to keep in mind while making that decision that a warning that is either off-by-default or turned off by nearly everyone delivers much less value than a warning that can be made on by default and that people don't turn off. Are there open-source projects making use of CTAD on which we could perform an analysis?

>> I don't see a good general way to catch and warn on bugs like `vector<string> v("foo", "bar")`
> 
> You mean `vector v("foo", "bar")`.

Hmm, I think I was actually thinking of cases more like:

  vector<string> s = {{"foo", "bar"}};

... which I have seen come up quite a lot.


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

https://reviews.llvm.org/D56731





More information about the cfe-commits mailing list